Long-running Jobs
Long-running Jobs
When an operation takes a part of a second (that's the typical workflow rule response time), or even few seconds, the user can wait until the operation is complete. But when an operation may take minutes or even hours to complete, it should take place "offline", without forcing the user to wait. Examples of such long-running operations include generating large reports, performing batch database updates, or transferring drawing files to/from a remote system.
These long-running operations should be implemented as jobs . Like message rule, jobs are invoked by interactive users. Like scheduled rules, jobs run in the background, without blocking users from performing other tasks.
The user can start the job, get a confirmation that the job has started, and then perform other tasks - while the job is executing. Later the user can check the job status to see if it is complete. The job status contains information about whether the job has been completed, its completion percent, its current processing step (for example, printing page 5 out of 20), and any result data produced by the job (for example, URLs to files generated by the job).
Job Implementation
Jobs are implemented as service methods. They can use exactly the same Web Central API as workflow rule services. In addition, they can update the job status.
Invoking Jobs
Like workflow rules, jobs can be invoked from view commands or from Java Script. After the job is started, the command will display the Job Progress dialog. The dialog will graphically show the job execution progress, and allow the user to stop the job if necessary.
Jobs can also be started using a special URL, so that the user can start them by clicking on a Navigator task. In this case, the Single Job view will be displayed while the job is executing. This view also shows the job execution progress. It allows the user to stop the job. If the job is not responding to stop requests, the user may have an option to forcefully terminate the job execution thread.
Use Cases
You can use the following table to determine when to use rules or jobs:
Use Case | Implementation |
---|---|
The operation is started by the user and takes no more than 10 seconds. |
Implement as message rule . |
The operation is started by the user and takes up to few minutes. |
Implement as job , use with a job progress dialog. |
The operation is started by the user and may take more than few minutes. |
Implement as job , use with the Single Job view. |
The operation should be performed automatically, at scheduled time intervals. |
Implement as scheduled rule . |
Note that in all cases the rules or jobs are implemented as Java service methods.