Developer corner

Target group: Developers

Start instances

Sometimes it is necessary to start instances in a JobRouter® installation programmatically. An API and a start command are available for this use case.

Instances are started asynchronously when submitting a form and using the form finisher since a JobRouter® installation may be unavailable or in maintenance mode and to avoid long page loads. Let’s take a look at the flow:

Transferring data sets

Transferring data sets

As you can see from the diagram, you can prepare multiple instances. The different instances can be started on different JobRouter® installations – depending on the configuration of the step link in the Process module.

Preparing the instance data

If you want to start instances programmatically in a JobRouter® installation, you can use the Preparer class within TYPO3, for example in an Extbase controller:

 4namespace MyVendor\MyExtension\Controller;
 6use Brotkrueml\JobRouterProcess\Domain\Dto\Transfer;
 7use Brotkrueml\JobRouterProcess\Domain\Repository\StepRepository;
 8use Brotkrueml\JobRouterProcess\Exception\PrepareException;
 9use Brotkrueml\JobRouterProcess\Transfer\Preparer;
10use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
12final class MyController extends ActionController
14   public function __construct(
15      private readonly Preparer $preparer,
16      private readonly StepRepository $stepRepository,
17   ) {
18   }
20   public function myAction()
21   {
22      // ... some other code
24      // First get the step link uid from the step handle.
25      // It is advised to use the handle because the step link uid can differ
26      // from development to production system (it is an auto increment).
27      $step = $this->stepRepository->findByHandle('your_step_handle');
29      // Define the transfer DTO with your parameters
30      // Have a look in the Domain\Dto\Transfer class to see the available setters
31      $transfer = new Transfer(time(), $step->getUid(), 'my-correlation-id);
32      $transfer->setType('Demo');
33      $transfer->setSummary('My summary');
34      $transfer->setProcesstable(
35         \json_encode([
36            'name' => 'John Doe',
37            'company' => 'Acme Ltd.',
38            'email_address' => '',
39            'message' => 'Please send me information.',
40         ])
41      );
43      try {
44         $this->preparer->store($transfer);
45      } catch (PrepareException $e) {
46         // On errors an exception can be thrown
47         var_dump($e->getMessage());
48      }

The start command must be activated with a cron job to periodically start instances in the JobRouter® installation(s).