Developer corner¶
Target group: Developers
Table of Contents
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¶
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, e.g. in an Extbase
controller:
1<?php
2declare(strict_types=1);
3
4namespace Vendor\Extension\Controller;
5
6use Brotkrueml\JobRouterProcess\Domain\Model\Transfer;
7use Brotkrueml\JobRouterProcess\Domain\Repository\StepRepository;
8use Brotkrueml\JobRouterProcess\Exception\PrepareException;
9use Brotkrueml\JobRouterProcess\Transfer\Preparer;
10use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
11
12final class MyController extends ActionController
13{
14 private Preparer $preparer;
15 private StepRepository $stepRepository;
16
17 // It's important to use dependency injection to inject all necessary
18 // dependencies
19 public function __construct(
20 Preparer $preparer,
21 StepRepository $stepRepository
22 ) {
23 $this->preparer = $preparer;
24 $this->stepRepository = $stepRepository;
25 }
26
27 public function myAction()
28 {
29 // ... some other code
30
31 // First get the step link uid from the step handle.
32 // It is advised to use the handle because the step link uid can differ
33 // from development to production system (it is an auto increment).
34 $step = $this->stepRepository->findOneByHandle('your_step_handle');
35
36 // Define the transfer domain model with your parameters
37 // Have a look in the Transfer model to see the available setters
38 $transfer = new Transfer();
39 $transfer->setCrdate(time());
40 $transfer->setStepUid($step->getUid());
41 $transfer->setType('Demo');
42 $transfer->setSummary('My summary');
43 $transfer->setProcesstable([
44 'name' => 'John Doe',
45 'company' => 'Acme Ltd.',
46 'email_address' => 'jdoe@example.com',
47 'message' => 'Please send me information.',
48 ]);
49
50 try {
51 $this->preparer->store($transfer);
52 } catch (PrepareException $e) {
53 // On errors an exception can be thrown
54 var_dump($e->getMessage());
55 }
The start command must be activated with a cron job to periodically start instances in the JobRouter® installation(s).
Instead of the Preparer
class, you can also use the
Brotkrueml\JobRouterProcess\Domain\Repository\TransferRepository
to store
transfer records in the database.