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.

Diagram illustrating the flow between ControllerCommand1, Scheduler, and ControllerCommand2 explained in the following paragraph.

The flow shown in the preceding diagram is as follows:

  1. ControllerCommand1 is executed as a result of a URL request.
  2. ControllerCommand1 adds a job to the Scheduler. The job is ControllerCommand2. ControllerCommand1 returns a view, immediately after adding the job to the Scheduler.
  3. 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.