Search in sources :

Example 1 with OScheduledEvent

use of com.orientechnologies.orient.core.schedule.OScheduledEvent in project serverless by bluenimble.

the class OrientDatabase method schedule.

@Override
public void schedule(String event, Query query, String cron) throws DatabaseException {
    if (query == null || Lang.isNullOrEmpty(query.entity()) || query.construct() == null) {
        throw new DatabaseException("query to schedule should provide the entity name and the construct [insert, update or delete]");
    }
    try {
        OScheduler sch = db.getMetadata().getScheduler();
        OScheduledEvent oEvent = sch.getEvent(event);
        if (oEvent != null) {
            sch.removeEvent(event);
        }
        sch.scheduleEvent(new OScheduledEventBuilder().setName(event).setRule(cron).setFunction(newFunction(event, query)).build());
    } catch (Exception ex) {
        throw new DatabaseException(ex.getMessage(), ex);
    }
}
Also used : OScheduledEventBuilder(com.orientechnologies.orient.core.schedule.OScheduledEventBuilder) OScheduler(com.orientechnologies.orient.core.schedule.OScheduler) DatabaseException(com.bluenimble.platform.db.DatabaseException) OScheduledEvent(com.orientechnologies.orient.core.schedule.OScheduledEvent) IOException(java.io.IOException) DatabaseException(com.bluenimble.platform.db.DatabaseException)

Aggregations

DatabaseException (com.bluenimble.platform.db.DatabaseException)1 OScheduledEvent (com.orientechnologies.orient.core.schedule.OScheduledEvent)1 OScheduledEventBuilder (com.orientechnologies.orient.core.schedule.OScheduledEventBuilder)1 OScheduler (com.orientechnologies.orient.core.schedule.OScheduler)1 IOException (java.io.IOException)1