Step 20 of 21 · 4 minutes

Replacing Outdated Jobs

The Scenario

A customer updated their address AFTER submitting a credit card application, but BEFORE the job processed. The pending job has the old address.

We need to update the job with the new information.

The Challenge

How do we update or replace a job that's already enqueued or even processing?

The Solution

Use enqueueOrReplace() to update existing jobs:


// Create job with a unique ID
UUID jobId = JobProId.fromIdentifier(customer.getEmail());
jobScheduler.enqueue(jobId, () -> processApplication(customer));

// Later, customer updates their info...
customer.setAddress(newAddress);

// Replace the job with updated data
jobScheduler.enqueueOrReplace(jobId, () -> processApplication(customer));

If the job is already processing, it will be interrupted and restarted with the new data!

Read the documentation →

Try It Yourself

  1. Register a credit card
  2. Immediately update the registration with new details
  3. Watch the job get replaced in the dashboard!
You need to log in to perform write operations. You can still view the code solution and dashboard.
Loading code...