PHP code example of tomatom / jobqueuebundle
1. Go to this page and download the library: Download tomatom/jobqueuebundle library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tomatom / jobqueuebundle example snippets
TomAtom\JobQueueBundle\JobQueueBundle::class => ['all' => true]
$commandName = 'app:your:command';
$params = [
'--param1=' . $request->get('param1'),
'--param2=' . $request->get('param2'),
];
// Try to create the command job
try {
$job = $this->commandJobFactory->createCommandJob($commandName, $params);
} catch (OptimisticLockException|ORMException|CommandJobException $e) {
// Redirect back upon failure
$this->logger->error('createCommandJob error: ' . $e->getMessage());
return $this->redirectToRoute('your_route');
}
// Redirect to the command job detail
return $this->redirectToRoute('job_queue_detail', ['id' => $job->getId()]);
$job = $this->commandJobFactory->createCommandJob($commandName, $params, $customer->getId(), Customer::class);
// Retrieve another job entity to add as a parent job
$parentJob = $this->entityManager->getRepository(Job::class)->findOneBy(['command' => $command, 'status' => Job::STATUS_COMPLETED]);
$job = $this->commandJobFactory->createCommandJob($commandName, $params, null, null, $parentJob);
$startAt = DateTimeImmutable::createFromFormat('Y-m-d\TH:i', $postponedDateTime);
$job = $commandJobFactory->createCommandJob($commandName, $params, $listId, $listName, null, null, $startAt);
$jobRecurring = $this->entityManager->getRepository(JobRecurring::class)->find($id);
if ($jobRecurring) {
$commandJobFactory->updateRecurringCommandJob($jobRecurring, $commandName, $params, $frequency, $active);
} else {
$commandJobFactory->createRecurringCommandJob($commandName, $params, $frequency, $active);
}
$io->info(Job::COMMAND_OUTPUT_PARAMS . $customerId) // $customerId = 123;
$customer = $this->entityManager->getRepository(Customer::class)->find($job->getOutputParams());
$io->info(Job::COMMAND_OUTPUT_PARAMS . 123);
$io->info(Job::COMMAND_OUTPUT_PARAMS . 'some text value');
$io->info(Job::COMMAND_OUTPUT_PARAMS . implode(['a', 'b']));
shell
php bin/console messenger:consume job_message
shell
php bin/console messenger:consume scheduler_job_recurring