Hi. I have these jobs and I need to check a condition before running jobs. If the condition is true, the job should be created and run. If it is false, no
this is my solution. But (example: cron 0/10 * * * * ?) every 10 second trigger working and try to create job then again a check conditon. as a result requests to the database are increasing.(load trigger and jobs from DB)
Best Solutin: When project run first time check ccondition and if condtion true working normally If it is false not work at all (jobs and triggers should not be added to the Scheduler) and dont send any requests to database. (for load trigger and jobs from DB)
It is possible? if possible,How?
Hi
My 2 cents. With quartz you call a job under no condition. Just stupid, every 10 seconds.
And in this job, you check the condition ( and can even log what and when and why you did or did not execute the work ) and execute then work needed to be done if all conditions are true.
You have to work in layers.
Just as an idea
Regards
Felix
just example
Hello Tohir,
Perhaps in your case you need to manually exclude a trigger from the scheduler after you have checked the start conditions of the application. Look in the quartz documentation for the scheduler.unscheduleJob
method.
Thanks,
Ilya
Hi.
I used this method
But my TeamLead said that "if conditon false Triggers and Jobs not loaded from db and not added to schedular is it Possible?
The addon does not interact with the database in any way, bypassing Quartz. It provides scripts to create tables, where Quartz stores data, but otherwise all interaction with the database is done through Quartz. The UI of the addon displays (or creates new) Dto’s received from the Quartz api.
So the logic of working with Quartz depends on the requirements of a particular application. And for more complex scenarios, it is better to look at the library documentation. Jmix simply provides a convenient interface to interact with the Quartz.
Thanks
Hi. I have a another question. Project runs in 3 instances. I use scheduler.pauseTrigger(key) this method paused trigger and store databse, or use scheduler.unscheduleJob(key) this method remove trigger from database.
Problem: In one instance, the condition is true and the job should run normally, in the other 2 instances, the condition is false and the job should not run. But I use pausedTrigger() or unscheduleJob() method one Instance and this is affecting other instances
You really should outsource the decision what to do to the instances themselves and use quartz just for triggering every 10 seconds these checks …
Regards
Felix
Hi, Tohir
If you configured clusterization correctly (e.g. specified spring.quartz.job-store-type=jdbc in application.properties, although this may be enabled by default in jmix configuration) job will run only on one instance at the same time. If you still want to have replicated condition value you must use distributed cache(hazelcast) or database(as quartz does) to store and read it.
wbr, Aleksey