Long-running controller commands
If a controller command takes a long time to execute, you can split the command into two commands. The first command, which is executed as the result of a URL request, simply adds the second command to the Scheduler, so that it runs as a background job.
The flow shown in the preceding diagram is as follows:
- ControllerCommand1 is executed as a result of a URL request.
- ControllerCommand1 adds a job to the Scheduler. The job is ControllerCommand2. ControllerCommand1 returns a view, immediately after adding the job to the Scheduler.
- The Scheduler executes ControllerCommand2 as a background job.
In this scenario, the client typically polls the result from ControllerCommand2. ControllerCommand2 should write the job state to the database.