Execute a job on DateTime

Hi,

I have an entity with a DateTime field (fireDate).
This fireDate can be changed to the users to a new value (only a date in the future).
Everytime the current date equals the fireDate, fireXYZ() should be executed.

How to do this?

I was thinking about creating a quartz job and then adding (or removing/changing) ‘Execute once’ triggers?
But how to add/remove/change quartz job triggers in the background by the process?

Thanks,
Dirk

Jmix version: 2.4.2
Jmix Studio plugin version: 2.4.2-243
IntelliJ version: IntelliJ IDEA 2024.3.1.1

Hello,

how to add/remove/change quartz job triggers in the background by the process
Yes, there are ways, for example, I’m adding user defined alarms and then scheduling the quartz jobs.

But, for your case, I think you can do something simpler:

  • have a table (you have already), with fire date or dates, that user can manage - that’s simple, jmix generates UI for that without problems
  • then schedule a permanent quartz job, that fires once per day, and iterates through the table, and checks if today equals the date
  • if yes, call your business logic methods

Kind regards,
Mladen

Hi Mladen,

The fireDate is a DateTime field and can be changed multiple times per day.
If the fireDate is 2025-02-12 14:25:00, then the process must be started at that DateTime.
I don’t want a quartz job running every second to check if the process needs to be started.

If the fireDate is changed by the user it should delete any existing triggers from the quartz job and add a new ‘Execute once’ trigger for the new fireDate.
Any idea (example) how to do this?

Thanks