Skip to content

Commit 99c2a65

Browse files
committed
fix: correct bad merge
1 parent 3ee2cd6 commit 99c2a65

12 files changed

+75
-23
lines changed

Command/AddRecurringConsoleJobToQueueCommand.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ private function addRecurringJobs(OutputInterface $output)
106106
continue;
107107
}
108108
}
109+
110+
$command = $configuration->getCommand();
111+
$arguments = [];
112+
113+
// i.e. does the command already have options or arguments within the string
114+
if (stripos($configuration->getCommand(), ' ') !== false) {
115+
$command = trim(strstr($configuration->getCommand(), ' ', true));
116+
$arguments = explode(' ', trim(strstr($configuration->getCommand(), ' ', false)));
117+
}
118+
109119
$this->jobManager->addConsoleCommandJob(
110-
$configuration->getCommand(),
111-
[],
120+
$command,
121+
$arguments,
112122
$configuration->getTopic(),
113123
$configuration->getTimeout(),
114124
$configuration->getTimeout()

Command/AddScheduleJobToQueueCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Markup\JobQueueBundle\Command;
44

5+
use Markup\JobQueueBundle\Entity\ScheduledJob;
56
use Markup\JobQueueBundle\Service\JobManager;
67
use Markup\JobQueueBundle\Service\ScheduledJobService;
78
use Psr\Log\LoggerInterface;
@@ -55,12 +56,18 @@ protected function configure()
5556

5657
protected function execute(InputInterface $input, OutputInterface $output)
5758
{
58-
if ($jobs = $this->scheduledJobService->getUnqueuedJobs()) {
59+
$jobs = $this->scheduledJobService->getUnqueuedJobs();
60+
61+
if ($jobs) {
5962
foreach ($jobs as $job) {
63+
if (!$job instanceof ScheduledJob) {
64+
continue;
65+
}
66+
6067
try {
6168
$this->jobManager->addConsoleCommandJob(
6269
$job->getJob(),
63-
[],
70+
$job->getArguments(),
6471
$job->getTopic(),
6572
3600,
6673
3600

Entity/ScheduledJob.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,20 @@ class ScheduledJob
4141
private $updated;
4242

4343
/**
44-
* @param mixed $job
44+
* @var array
45+
*/
46+
private $arguments;
47+
48+
/**
49+
* @param string $job
50+
* @param array $arguments
4551
* @param mixed $scheduledTime
4652
* @param mixed $topic
4753
*/
48-
function __construct($job, $scheduledTime, $topic)
54+
function __construct(string $job, array $arguments, $scheduledTime, $topic)
4955
{
5056
$this->job = $job;
57+
$this->arguments = $arguments;
5158
$this->scheduledTime = $scheduledTime;
5259
$this->topic = $topic;
5360
$this->queued = false;
@@ -78,6 +85,11 @@ public function getJob()
7885
return $this->job;
7986
}
8087

88+
public function getArguments(): array
89+
{
90+
return $this->arguments;
91+
}
92+
8193
/**
8294
* @return string
8395
*/

Job/ConsoleCommandJob.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function run(ParameterBagInterface $parameterBag): string
2222
ini_set('max_execution_time', 7200);
2323
$command = [];
2424

25+
$command[] = $parameterBag->get('markup_job_queue.php_bin_path');
2526
$command[] = $this->getConsolePath($parameterBag->get('markup_job_queue.console_dir'));
27+
$command[] = $this->getCommand();
2628

27-
$command[] = $this->args['command'];
28-
29-
foreach ($this->args['arguments'] as $argument) {
29+
foreach ($this->getArguments() as $argument) {
3030
$command[] = $argument;
3131
};
3232

@@ -57,7 +57,7 @@ public function run(ParameterBagInterface $parameterBag): string
5757
if (!$process->isSuccessful()) {
5858
$message = sprintf(
5959
'A job `%s` failed with topic `%s` with output:%s and the error output: %s',
60-
$this->args['command'],
60+
$this->getCommand(),
6161
$this->topic,
6262
$process->getOutput(),
6363
$process->getErrorOutput()
@@ -102,6 +102,11 @@ public function getCommand()
102102
return $this->getArgs()['command'];
103103
}
104104

105+
public function getArguments(): array
106+
{
107+
return $this->getArgs()['arguments'] ?? [];
108+
}
109+
105110
/**
106111
* @param string $kernelDir
107112
* @return string

Model/Job.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class Job
2121
* @param string $topic
2222
*/
2323
final public function __construct(
24-
array $args = array(),
24+
array $args = [],
2525
$topic = 'default'
2626
) {
2727
$this->args = $args;

Model/ScheduledJobRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
interface ScheduledJobRepositoryInterface
88
{
99
/**
10-
* @return mixed
10+
* @return iterable<ScheduledJob>
1111
*/
1212
public function fetchUnqueuedJobs();
1313

Publisher/JobPublisher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function publish(Job $job)
8383
// log the job as existing
8484
if ($job instanceof ConsoleCommandJob) {
8585
$uuid = Uuid::uuid4()->toString();
86-
$log = new JobLog($job->getCommand(), $uuid, $job->getTopic());
86+
$log = new JobLog(trim(sprintf('%s %s', $job->getCommand(), implode(' ', $job->getArguments()))), $uuid, $job->getTopic());
8787

8888
$this->jobLogRepository->add($log);
8989

Resources/config/doctrine/ScheduledJob.orm.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ Markup\JobQueueBundle\Entity\ScheduledJob:
1010
fields:
1111
job:
1212
type: string
13-
length: 2048
13+
length: 256
14+
arguments:
15+
type: array
1416
topic:
1517
type: string
1618
length: 60

Resources/config/services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
parameters:
2+
markup_job_queue.php_bin_path: '/usr/bin/php'
3+
14
services:
25
markup_job_queue.publisher:
36
class: Markup\JobQueueBundle\Publisher\JobPublisher

Service/JobManager.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,29 @@ public function addConsoleCommandJob(string $command, array $arguments = [], $to
6969

7070
/**
7171
* Adds a named command to the job queue at a specific datetime
72-
* @param string $command A valid command for this application.
73-
* @param \DateTime $dateTime The DateTime to execute the command.
74-
* @param string $topic The name of a valid topic.
75-
* @param int $timeout The amount of time to allow the command to run.
76-
* @param int $idleTimeout The amount of idle time to allow the command to run. Default to the same as timeout.
72+
*
73+
* @param string $command A valid command for this application.
74+
* @param \DateTime $dateTime The DateTime to execute the command.
75+
* @param array $arguments
76+
* @param string $topic The name of a valid topic.
77+
* @param int $timeout The amount of time to allow the command to run.
78+
* @param int $idleTimeout The amount of idle time to allow the command to run. Default to the same as timeout.
7779
*/
78-
public function addScheduledCommandJob(
80+
public function addScheduledConsoleCommandJob(
7981
$command,
8082
\DateTime $dateTime,
83+
array $arguments = [],
8184
$topic = 'default',
8285
$timeout = 60,
8386
$idleTimeout = null
8487
) {
88+
if (stripos($command, " ") !== false) {
89+
throw new \InvalidArgumentException('Console command is not expected to have spaces within the name');
90+
}
91+
8592
$args = [];
8693
$args['command'] = $command;
94+
$args['arguments'] = $arguments;
8795
$args['timeout'] = $timeout;
8896
$args['idleTimeout'] = $idleTimeout ?? $timeout;
8997
$job = new ConsoleCommandJob($args, $topic);

0 commit comments

Comments
 (0)