reugn/go-quartz

No Restriction on Jobs with Same Key

Hoteliar opened this issue · 5 comments

Tried to insert 2 jobs with same key (int), both of them were inserted. But the GetScheduledJob by ID only returns one job.
I expect the second will override the first one.

pires commented

IIUC the same problem happens if you delete by ID, where only the first Job found w/ said ID is deleted but others stay scheduled. That said, I'm currently thinking ensuring only one job with a certain ID is present by always overwriting seems like the sane thing to do.

reugn commented

The original Java Quartz throws an exception on a duplicate job being scheduled. The current architecture would require a full scan of all scheduled jobs to detect duplicates, which is inefficient. It's possible to explicitly call the DeleteJob before scheduling a job to check for uniqueness. But this requires the user to be aware of the possible problem with duplicating jobs.

pires commented

Could DeleteJob return the deleted instance? This way one could:

job, _ := DeleteJob(id)
for job != nil {
    job, _ = DeleteJob(id)
}
// no jobs w/ ID=id

Note: for the sake of making my point in a succinct way, I'm not handling errors.

If this doesn't look crazy, it could even be added as an helper to this lib, eg ClearJob(id)?

reugn commented

Yes, this one would work, but it's odd and wrong to have this functionality hidden from the user. In the meantime, the only error returned is the "No Job found" which could be an indicator. I would keep this open to wait for proper refactoring to handle the job duplication issue.

pires commented

Maybe a stop-gap solution could be to comment the function definitions to warn about this and maybe point to this issue as a TODO?