michelsalib / BCCResqueBundle

The BCC resque bundle provides integration of php-resque to Symfony2. It is inspired from resque, a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later.
122 stars 91 forks source link

Create job from a service #99

Closed vamsiikrishna closed 10 years ago

vamsiikrishna commented 10 years ago

Hi,

I am able to create jobs from the controller, but how do I create a job from a service ?

I am trying to pass @bcc_resque.resque in the arguments field of my service declaration, but not sure which class would be sent as arguments in the service constructor .

Thanks

mrbase commented 10 years ago

it will be BCC\ResqueBundle\Resque so you can add jobs like this:

use BCC\ResqueBundle\Resque;
use BCC\ResqueBundle\job;

// ...
public function __construct(Resque $resque)
{
    $this->resque = $resque;
}

public function addJob()
{
    $this->resque->enqueue(new Job());
}

If you are ever in doubt about which class is injected into a method, you can always use get_class($somevar) to get it.

vamsiikrishna commented 10 years ago

@mrbase thanks a lot !

mrbase commented 10 years ago

no problem, will close this