Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created November 18, 2013 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bwaidelich/7529881 to your computer and use it in GitHub Desktop.
Save bwaidelich/7529881 to your computer and use it in GitHub Desktop.
Example usage for the ``TYPO3.JobQueue.Common`` TYPO3 Flow package (JobManager)
<?php
namespace Acme\JobQueueTest;
/* *
* This script belongs to the TYPO3 Flow package "Acme.JobQueueTest". *
* *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Utility\Files;
use TYPO3\Jobqueue\Common\Job\JobInterface;
use TYPO3\Jobqueue\Common\Queue\Message;
use TYPO3\Jobqueue\Common\Queue\QueueInterface;
class PdfJob implements JobInterface {
/**
* @var string
*/
protected $text;
/**
* @param string $text
*/
public function __construct($text) {
$this->text = $text;
}
/**
* Execute the job
* A job should finish itself after successful execution using the queue methods.
*
* @param QueueInterface $queue
* @param Message $message The original message
* @return boolean TRUE if the job was executed successfully and the message should be finished
*/
public function execute(QueueInterface $queue, Message $message) {
$filename = uniqid('pdf') . '.txt';
file_put_contents(Files::concatenatePaths(array(FLOW_PATH_DATA, $filename)), $this->text);
return TRUE;
}
/**
* Get an optional identifier for the job
*
* @return string A job identifier
*/
public function getIdentifier() {
return NULL;
}
/**
* Get a readable label for the job
*
* @return string A label for the job
*/
public function getLabel() {
return 'PDF Job';
}
}
TYPO3:
Jobqueue:
Common:
queues:
'test':
className: 'TYPO3\Jobqueue\Beanstalkd\Queue\BeanstalkdQueue' # or TYPO3\Jobqueue\Redis\Queue\RedisQueue, ...
<?php
namespace Acme\JobQueueTest\Controller;
/* *
* This script belongs to the TYPO3 Flow package "Acme.JobQueueTest". *
* *
* */
use Acme\FirstPackage\PdfJob;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\Controller\ActionController;
class StandardController extends ActionController {
/**
* @Flow\Inject
* @var \TYPO3\Jobqueue\Common\Job\JobManager
*/
protected $jobManager;
/**
* @param string $text
* @return void
*/
public function indexAction($text = 'default') {
$this->createPdf($text);
return 'Done!';
}
/**
* @param string $text
* @return void
*/
public function createPdf($text) {
$pdfJob = new PdfJob($text);
$this->jobManager->queue('test', $pdfJob);
}
}
@bwaidelich
Copy link
Author

Usage:

 git clone git://git.typo3.org/Packages/TYPO3.Jobqueue.Common.git
 git clone git://git.typo3.org/Packages/TYPO3.Jobqueue.Beanstalkd.git
 composer require pda/pheanstalk

 ./flow job:list test
 ./flow job:work test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment