The documentation says
Only use Workflow.currentTimeMillis() to get the current time inside a
Workflow.
Does it apply only to workflows or activities as well? Can I use System.currentTimeMillis() in activity implementation?
The implementation constraints mentioned in docs applies to workflows and not the activities. System.currentTimeMillis() can be used in an activity implementation. OP here.
Related
Say i have job which needs to be executed at fixed times in a day like below,
"05:00, 06:10, 07:30, 08:15, 09:05, 10:35"
How could i build a Trigger for this in Quartz ?
I couldnt find the way to achieve this out-of-the-box.
I see two ways to solve your problem:
1. Multiple triggers (recommended).
The most obvious and easy way to set the unusual scheduling for you job is to combine several triggers.
Quartz allows to set as much triggers as you want for single JobDetail.
2. Implement your own trigger.
It is more complicated way, applicable only if you must use only one trigger.
You could implement org.quartz.Trigger interface or any subinterfaces to set yourown rules.
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.
I would like to ask if there is a relationship between the Workflow and Importing of Files.
For example, the execution of workflow occurs when a record is saved, and it applies to updated records. And the action is to update a certain field on the target module if a specific field is changed. Say for example, Field A is updated to YES if field B is changed.
So it works well, when I manually saved the module after updating the field B.
How about during importing? Will the workflow would still matter? Provided that all conditions were successfully met.
I hope you could help me on this. I need to update our TS if there's a need for hard coding to support this.
Actually I have already posted this on the sugar forums. :D
Thanks so much!
Workflows are triggered with a before_save logic hook.
Logic hooks are triggered anytime the save() function is called
Creating records via the import process calls the the save() function.
So, yes, importing records will trigger your workflows.
The short answer is yes. There is no long answer.
Sugar uses the SugarBean class to save records, and it handles workflow. So if you save through Sugar, import, or use web services they all use SugarBean so therefore handle workflow.
I'm working on a project with Quartz and has been a problem with the dependencies with jobs.
we have a setup where A and B aren't dependent on eachother, though C is:
A and B can run at the same time, but C can only run when both A and B are complete.
Is there a way to set this kind of scenario up in Quartz, so that C will only trigger when A and B finish?
Not directly AFAIK, but it should be not too hard to use a TriggerListener to implement such a functionality (a TriggerListener is run both a start and end of jobs, and you can set them up for individual triggers or trigger groups).
EDIT: there is even a specific FAQ Topic about this problem:
There currently is no "direct" or "free" way to chain triggers with
Quartz. However there are several ways you can accomplish it without
much effort. Below is an outline of a couple approaches:
One way is to use a listener (i.e. a TriggerListener, JobListener or
SchedulerListener) that can notice the completion of a job/trigger and
then immediately schedule a new trigger to fire. This approach can get
a bit involved, since you'll have to inform the listener which job
follows which - and you may need to worry about persistence of this
information. See the listener
org.quartz.listeners.JobChainingJobListener which ships with Quartz -
as it already has some of this functionality.
Another way is to build a Job that contains within its JobDataMap the
name of the next job to fire, and as the job completes (the last step
in its execute() method) have the job schedule the next job. Several
people are doing this and have had good luck. Most have made a base
(abstract) class that is a Job that knows how to get the job name and
group out of the JobDataMap using pre-defined keys (constants) and
contains code to schedule the identified job. This abstract Job's
implementation of execute() delegates to an abstract template method
such as "doWork()" (where the extending Job class's real work goes)
and then it contains the code for scheduling the follow-up job. Then
they simply make extensions of this class that included the work the
job should do. The usage of 'durable' jobs, or the overloaded
addJob(JobDetail, boolean, boolean) method (added in Quartz 2.2) helps
the application define all the jobs at once with their proper data,
without yet creating triggers to fire them (other than one trigger to
fire the first job in the chain).
In the future, Quartz will provide a much cleaner way to do this, but
until then, you'll have to use one of the above approaches, or think
of yet another that works better for you.
I have 7 workflow that need to execute; that need to run in certain order ? Is there any scheduling service for this in wf4 or any other approach i can use?
Ocean
If you need to run them sequentially in a certain order, why not just create another workflow and put all 7 of your workflows as activities in a top sequential activity?
If you create an activity that derives fron NativeActivity you can schedule child activities in any order you like. That is the closest thing to a "SchedulerService" I can think of.
However you have to know the activites you want to run at compile time. You can only arrange the order differently using this approach.
If you don't know which activities you want to use at compile time you could use a parent/child technique I showed on my blog WF4 How To Invoke a Child Workflow as XAML