Created
August 18, 2011 14:37
-
-
Save jessegreathouse/1154182 to your computer and use it in GitHub Desktop.
How to create a job in the NineThousandJobqueueBundle code
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 MyApp\MyBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use NineThousand\Jobqueue\Job\StandardJob as Job; | |
use NineThousand\Bundle\NineThousandJobqueueBundle\Vendor\Doctrine\Adapter\Job\Symfony2DoctrineJobAdapter as JobAdapter; | |
use NineThousand\Bundle\NineThousandJobqueueBundle\Entity\Job as JobEntity; | |
class DefaultController extends Controller | |
{ | |
public function indexAction() | |
{ | |
$jobAdapter = new JobAdapter( | |
$this->container->getParameter('jobqueue.adapter.options'), | |
new JobEntity(), | |
$this->getDoctrine()->getEntityManager(), | |
$this->get('logger') | |
); | |
//once you have the job adapter you can instantiate a new job | |
$job = new Job($jobAdapter); | |
//set the important job parameters like executable | |
$job->setExecutable('/home/users/mySite.com/app/console help'); | |
$job->setType('SymfonyConsoleJobControl'); | |
$job->setMaxRetries(10); | |
$job->setCooldown('1000'); | |
$job->setArgs(array('--help')); | |
//get the queueControl service | |
$queueControl = $this->get('jobqueue.control'); | |
//Its better to have the queue service adopt the job rather than setting it for a queue manually | |
//adopting a job will automatically set the correct job queue for that job | |
//to make the job active | |
$queueControl->getActiveQueue()->adoptJob($job); | |
//to put it in the retry queue | |
$queueControl->getRetryQueue()->adoptJob($job); | |
return $this->render('myBundle:Default:index.html.twig', array( | |
'activeQueue' => $queueControl->getActiveQueue(), | |
'retryQueue' => $queueControl->getRetryQueue(), | |
'scheduleQueue' => $queueControl->getScheduleQueue(), | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment