Skip to content

Instantly share code, notes, and snippets.

@egobude
Forked from bwaidelich/PdfJob.php
Created May 27, 2014 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egobude/5b27db7adf7ae3a05eb3 to your computer and use it in GitHub Desktop.
Save egobude/5b27db7adf7ae3a05eb3 to your computer and use it in GitHub Desktop.
<?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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment