redis-server) or configure a remote instance.composer require david-garcia/resque-bundle:^1.1
AppKernel.php:
new DavidGarciaCat\BCCResqueBundle\BCCResqueBundle(),
config.yml:
bcc_resque:
redis:
host: '127.0.0.1'
port: 6379
password: null
database: 0
namespace AppBundle\Job;
use BCC\ResqueBundle\Job\Job as BaseJob;
class SendEmailJob extends BaseJob
{
public function perform($email, $message)
{
// Use Symfony services via $this->getContainer()
$mailer = $this->getContainer()->get('mailer');
$mailer->send(...);
}
}
$job = new SendEmailJob();
$job->enqueue(['user@example.com', 'Hello!']);
Or via command:
php app/console bcc:resque:enqueue AppBundle:Job:SendEmailJob 'user@example.com' 'Hello!'
BaseJob: All custom jobs must extend BCC\ResqueBundle\Job\Job.$this->getContainer().perform() as an array.$job->enqueueOn('critical', ['param1', 'param2']); // Custom queue
php app/console bcc:resque:worker default --verbose
(Replace default with your queue name.)$job->delay(3600); // Delay 1 hour (seconds)
$job->at(new \DateTime('+1 day')); // Schedule for tomorrow
/_resque (configured route) to view:
$job = new ProcessOrderJob();
$job->enqueue([$orderId]);
autoRequeue in config to retry failed jobs with backoff:
bcc_resque:
auto_requeue: true
backoff_strategy: exponential
redis-cli ping).database config in bcc_resque to avoid key collisions.$job->enqueue([$entity->getId(), $entity->getName()]);
SIGTERM (not SIGKILL).redis-cli LRANGE resque:failed:count 0 -1
monolog to log job execution:
monolog:
handlers:
resque:
type: stream
path: "%kernel.logs_dir%/resque.log"
level: debug
php app/console bcc:resque:retry failed
bcc_resque:
workers_per_queue: 2
perform() for unique logic.BCC\ResqueBundle\Worker\Middleware\BaseMiddleware to add pre/post hooks.Resources/views/BCCResqueBundle/.redis-cli SET job:123 status "processing"
getContainer():
$translator = $this->getContainer()->get('translator');
How can I help you explore Laravel packages today?