Get access to system scheduler

Hi,

is there a legitimate way to access the system scheduler, the one that timer events are using?

I need to programmatically schedule a job that will start a process at a specific time, without a timer starting event.

Would import Quartz, but why extra library if the system has a scheduler already.

Regards,
fedd

Hi @fedd,

have a look at these methods: https://github.com/camunda-consulting/code/blob/master/snippets/email-incident-handler-plugin/src/main/java/com/camunda/consulting/email_incident_handler_plugin/EmailIncidentHandler.java#L75-L93

The new job will be saved by the mybatis-magic in the engine.

The complete snippets give some background information that might help you to adapt thsi to your use case.

Hope this helps, Ingo

1 Like

You could also model a second process with a timer start event that and a single service task that starts the actual process. Then you don’t have the timer event in the actual process model.

Thanks @Ingo_Richtsmeier, a little followup question… How do I unschedule a job? The TimerEntity class doesn’t seem to have a method to do this. The method

public void createNewTimerJob(Date dueDate) {
  // create new timer job
  TimerEntity newTimer = new TimerEntity(this);
  newTimer.setDuedate(dueDate);
  Context
    .getCommandContext()
    .getJobManager()
    .schedule(newTimer);
}

provokes me to hack a similar code to unschedule, and it might work as this all happens in an event listener => the command context may exist. Still I am afraid to use internals, @thorben obviously doesn’t encourag this =)

upd or is there a non-context way to get my hands on the Job Manager?..

@thorben, thanks. I am trying to make Camunda to start a process upon a task due date.

The task may eventually be deleted without being executed, so I need to unschedule the process starter if it wasn’t yet started (and delete if it was)

You can cancel jobs via ManagementService#deleteJob and process instances via RuntimeService#deleteProcessInstance.

Cheers,
Thorben

1 Like