How can I get the interval/schedule details of an existing trigger?
In our application a user can reschedule a job by setting an interval in minutes. We need to compare the value they submit with the schedule of the current trigger to determine whether a reschedule is required.
Check out Scheduler.getTrigger() method which returns an instance of Trigger. You can downcast it and read all required information like the schedule (CRON/simple) and associated job.
Related
I am trying to create a Quartz scheduler using Java which will be able to call an API and pass in data.
I am totally new to Quartz but now I understand the Job concept and how to create one. I understand the trigger concept and how to trigger one
and I understand how the scheduler works.
What I am having difficult with is how can I pass in the information which is required to be passed to the API. I have an example of an API being called and the data is entered into the DB but the information has been hard coded into the class be passed into the JobDetails.
Ie. the user passes a message to the system which needs to be sent to the user in 12 hours and not before, so what i was planning was create a Job and a trigger in to set the execute time to 12 hours. How to do i pass the message into the scheduler? Where should this message be stored? Is what I am trying to do possible? Have i misunderstood what Quartz is capable of doing?
Thank you for your time. Any assistance would be greatly appreciated.
Take a look at JobDataMap. If you are creating a new job for each user action you can store the message in there which will be available during the execution.
JobDataMap Holds state information for Job instances.
JobDataMap instances are stored once when the Job is added to a scheduler. They are also re-persisted after every execution of jobs annotated with #PersistJobDataAfterExecution.
JobDataMap instances can also be stored with a Trigger. This can be useful in the case where you have a Job that is stored in the scheduler for regular/repeated use by multiple Triggers, yet with each independent triggering, you want to supply the Job with different data inputs.
The JobExecutionContext passed to a Job at execution time also contains a convenience JobDataMap that is the result of merging the contents of the trigger's JobDataMap (if any) over the Job's JobDataMap (if any).
In case you have a single job but for each user action you are creating a new trigger, you can follow the solution given here.
Third option will be, for each user action, persist the message and time to send email to the database. Have a job that runs periodically and scans through database for eligible records for which email has to be sent
I have vtiger6.4 installed and smtp configuration is also done.When I create a new lead it sends the mail.I have created a Workflow for lead and selected Every time the record is modified email should be send to the assigned to.But it is not working.Suggest me some solution.
There are to option to trigger workflow on save event.
Every Time Record is saved
Every Time Record is modified
First is
Every Time Record is saved
This means even no field is updated and you just click save it will trigger workflow event.
You have selected
Every time the record is modified
So that means atleast one Field must be updated using Record Model Class. If you are updating it using query then Workflow will not be Triggered.
Now you have to choose which trigger event you want to choose. If still you have problem then possible that you have set condition in 2nd step. You can provide more details so can help you in better way.
Vtiger Email on workflows send email via cronjobs.
Read more at:
vTigerCRM 7 - Scheduler isn't running any cron jobs unless manually triggered
I have some functionality I need to implement in Dynamics Crm 2016. I need to scan all records for a custom entity and update any record where a certain condition is true. This is a bit too complex to do via a workflow (I can't change owner via a workflow step) so I'm thinking perhaps I could perform this logic in a custom plugin. I don't know if it makes sense to call this plugin from a workflow in crm though, as I need to perform the logic on all records for this particular entity, and I need the logic to run regularly, i.e. daily/weekly. What's the best way to do this?
I figured this out. It was actually possible to do entirely within Crm. What I was trying to do was the following.
I have a custom entity called announcement, and it has a custom field called embargo date.
I needed to somehow check periodically if the embargo date has been reached, meaning, is the embargo date today? If so, then I needed to change the owner of this entity.
If the embargo date has not yet been reached, then I need to wait until it is, checking the date again everyday till it is reached.
I managed this with a workflow. I added my check conditions, if they were true I assigned the entity to another user.
If my conditions weren't true, I added wait step to wait for 1 day,then another step to Start workflow where I called the current workflow recursively. Meaning, if the conditions aren't true have the workflow call itself again.
I saw the sample dynamic trigger in github and it is using fixed rate/delay but is it possible to implement dynamic trigger with cron expression where once job is completed with custom exit code we want the cron expression in such a way that it no longer poll for that day or change cron expressin to start polling from diff time onwards.
Unfortunately org.springframework.scheduling.support.CronTrigger uses final field, so we can't change its state at runtime. Therefore any ideas to seek the way how to change cron-expression value is a waste of time.
From other let's take a look at this as just a time producer solution to notify the scheduler when to start a provided task.
In other words here is a Trigger contract source code:
public interface Trigger {
Date nextExecutionTime(TriggerContext triggerContext);
}
So, what our solution must supply is just only returning the specific Date for each nextExecutionTime invocation.
Only what you need to do here is that dynamic trigger implementation which fits to your requirements.
Right, it might be a bit difficult to reach cron-similar behavior, but there is no choice for you right now...
Although you can stop() you adapter after the task, inject a new CronTrigger to it and start() it again.
You can write a custom trigger that simply wraps a CronTrigger and you can replace the delegate CronTrigger at will.
However, a limitation of the Trigger mechanism is you can't change an existing schedule.
If you are running your job on the poller thread, then you can change the trigger before the poller thread returns (and calls the trigger to find the next execution time).
Spring Integration 4.2 (currently at milestone 2) has conditional pollers which will make things like this a little easier.
How can we know if a trigger is scheduled to fire at a specific time? i searched through all the apis but couldnt find. The closest api I found is getNextFireTime() and getFireTimeAfter(Date afterTime). My requirement is to find that if a trigger is scheduled to fire at a specific time.. If not schedule it to fire at that time.
You could use the Quartz TriggerUtils utility methods.
The method computeFireTimes(org.quartz.spi.OperableTrigger trigg, Calendar cal, int numTimes) returns a list of Dates that are the next fire times of a Trigger.
The method computeFireTimesBetween(org.quartz.spi.OperableTrigger trigg, Calendar cal, java.util.Date from, java.util.Date to) returns a list of Dates that are the next fire times of a Trigger that fall within the given date range.
I hope this helps.