enragedginger/akka-quartz-scheduler

No public way to remove a schedule

refond opened this issue · 5 comments

Note: I refer to QuartzSchedulerExtension instance as scheduler

While using scheduler.cancelJob("MY_JOB_1") for a corresponding existing job, the job stops from firing as expected. There is no more reference to it in scheduler.runningJobs unlike scheduler.schedules which still holds a reference to the removed job !

A simple extra call to scheduler.removeSchedule("MY_JOB_1") would fix it, but this method is private.

To fix this with a minimum of impact on existing code I would propose adding the following method, with analogy to existing rescheduleJob

/**
* Unschedules an existing schedule
*
* Cancels the running job and all associated triggers and removes corresponding
* schedule entry from internal schedules map.
*
* @param name The name of the job, as defined in the schedule
* @return Success or Failure in a Boolean
*/
def unscheduleJob(name: String): Boolean = {
val isJobCancelled = cancelJob(name)
if (isJobCancelled) { removeSchedule(name) }
isJobCancelled
}

I briefly tested the above on a fork of your project and it works as expected.

What's your opinion ? Anything already available I overlooked ?

Hi @refond,

There has been interest in this feature in the past (i.e. #77), but no one has volunteered. Your approach sounds good. If you make a PR (with a couple of tests), I'll take a look at merging it in.

Thanks!

Hi @enragedginger,

Thanks for pointing at #77. I will do a PR as soon as I have managed to create some tests.

Regards

Hi @enragedginger,
I finally found time to make a PR #81 with corresponding tests. I have a bit extended the scope of the PR to include not only unscheduleJob aka deleteJobSchedule but also the corresponding create and update operations, using existing methods as building blocks.

Looking forward your feedback

@refond I've merged your changes and published build 1.8.0-akka-2.5.x. Thank you for your work on this!