DEPRECATION WARNING
This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.
Documentation¶
Job queues for TYPO3 CMS. This extension provides a simple in-memory queue and a cli or scheduler command to execute jobs.
This extension is a backport of the flow package Flowpack/jobqueue-common.
Note
You should install also one of the following extensions jobqueue_database, jobqueue_beanstalkd or jobqueue_redis.
Configuration¶
In the extension settings you can set the default queue class.
You can define for each queue different settings over TYPO3_CONF_VARS.
Example:
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['jobqueue']['myQueueName'] = [
'className' => 'R3H6\\JobqueueBeanstalkd\\Queue\\BeanstalkdQueue',
'options' => [
// Options are passed into the constructor of the queue
],
];
Creating a job¶
Jobs must implement the R3H6\Jobqueue\Job\JobInterface
interface which extends Serializable
itself.
Note
Jobs are getting serialized. It is recommended to serialize only data and no dependencies because queues could have a data limit.
Example:
<?php
namespace Vendor\ExtName\Job;
class MyJob implements \R3H6\Jobqueue\Job\JobInterface
{
protected $identifier;
protected $label = 'My job';
public function __construct($identifier)
{
$this->identifier = $identifier;
}
public function execute(\R3H6\Jobqueue\Queue\QueueInterface $queue, \R3H6\Jobqueue\Queue\Message $message)
{
// Do the job...
return true;
}
public function getIdentifier(){ return $this->identifier; }
public function getLabel(){ return $this->label; }
public function serialize()
{
// You must take care of serialization by yourself!
return serialize([$this->identifier]);
}
public function unserialize($data)
{
// You must take care of unserialization by yourself!
call_user_func_array([$this, '__construct'], unserialize($data));
}
}
Queue a job¶
When you created a job you can add the job to a queue over the JobManager
.
Example:
$myJob = GeneralUtility::makeInstance(\Vendor\ExtName\Job\MyJob::class, 'test');
$jobManager = GeneralUtility::makeInstance(ObjectManager::class)->get(JobManager::class);
$jobManager->queue('myQueueName', $myJob);
Executing a job¶
You can execute jobs over the ExtBase scheduler task "Jobqueue Job: work" or the cli command "extbase job:work".
Daemon¶
You can try to use the experimental scheduler task "Jobqueue Job: daemon". If you are using something like "upstart" you should call the cli command "extbase job:work" with "--limit=0".
Commands¶
typo3/cli_dispatch.phpsh extbase jow:work --queue-name --timeout --limit
$queueName: | The name of the queue to work on. |
---|---|
$timeout: | Seconds to wait for a job in the queue. |
$limit: | Number of jobs to be done, -1 for all jobs in queue, 0 for work infinite |
Signal and Slots¶
Signal Class Name | Signal Name | Located in Method | Passed arguments | Description |
R3H6\Jobqueue\Job\JobManager | jobFailed | waitAndExecute() | $queueName, R3H6JobqueueQueueMessage $message | Dispatched when a job fails and reached the max attemps. |
Differences to the flow package¶
- Namespace
- Jobs must satisfy also the
Serializable
interface.