mvniekerk / tokio-cron-scheduler

Schedule tasks on Tokio using cron-like annotation
Apache License 2.0
529 stars 59 forks source link

Could scheduler resume jobs execution after reload? #52

Open Dkwcs opened 1 year ago

Dkwcs commented 1 year ago

For now I see only one way to resume jobs execution after reloading service. I have added custom wrapper over metadata_storage to get all jobs ids then data and use this jobs data to recreate jobs and run them again. Maybe much more simple way exists?

azasypkin commented 1 year ago

Maybe much more simple way exists?

I would also be interested in a recommended approach for resuming jobs with tokio-cron-scheduler. Currently, I'm following a similar approach to what @Dkwcs is doing: fetching the job list and analyzing the extra to determine the specific job type: https://github.com/secutils-dev/secutils/blob/2f6c10bc5c47e0ef217fbd7874dd41ceda41ba8e/src/scheduler.rs#L79

Dkwcs commented 1 year ago

Also metadata_storage trait doesn't have get_all method, only get_by_id( It would be a lot easier to support jobs resume functionality if here no other ways exist.

ilxqx commented 1 year ago

The key point here is actually how to correspond to JobCode. I took a brief look at the source code, and the crucial implementation is the implementation of this trait JobCode.

We need to customize our own implementation of JobCode, but there is a technical challenge here. The ID of this Job needs to be generated by ourselves so that we have a chance to match it after program restarts. However, its internal actual implementation is creating a new UUID every time: let job_id = Uuid::new_v4();.

Looking forward to the author providing a good solution directly.

mvniekerk commented 3 months ago

@Dkwcs - the get_all method will definitely help in this regard, also to specify the GUID in creating a Job. Should be simple?