Replacing jobs
Is your job running with outdated information? Then just replace it...
Do you need to replace an already enqueued job? Or a job that is already being processed? Thanks to the JobRunr Pro enqueueOrReplace
and scheduleOrReplace
you can update the existing job easily.
UUID cityId = city.getId();
Observation observation = observationService.getLatestObservation(cityId); // the original observation
BackgroundJob.enqueue(myId, () -> weatherService.predictWeather(cityId, observation));
Observation observation = observationService.getLatestObservation(cityId); // the updated observation after a storm
BackgroundJob.enqueueOrReplace(myId, () -> weatherService.predictWeather(cityId, observation));
By default, JobRunr ignores jobs with an id that already exist in the JobRunr database. The reason for this is that JobRunr allows to create jobs from JMS messages in a load-balanced environment. By ignoring a job that already exists, we’re sure to run the job only once.