Created
November 18, 2013 15:39
-
-
Save bwaidelich/7529881 to your computer and use it in GitHub Desktop.
Example usage for the ``TYPO3.JobQueue.Common`` TYPO3 Flow package (JobManager)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TYPO3: | |
Jobqueue: | |
Common: | |
queues: | |
'test': | |
className: 'TYPO3\Jobqueue\Beanstalkd\Queue\BeanstalkdQueue' # or TYPO3\Jobqueue\Redis\Queue\RedisQueue, ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: