Skip to content

Commit

Permalink
Merge pull request #6 from savchuknikolay/fix-deprecations
Browse files Browse the repository at this point in the history
Fix deprecations
  • Loading branch information
Mark1Z authored Oct 9, 2020
2 parents 90b62c1 + 0ab3f59 commit c9cbf59
Show file tree
Hide file tree
Showing 31 changed files with 249 additions and 301 deletions.
14 changes: 3 additions & 11 deletions Command/RetryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class RetryCommand extends Command

/**
* RetryCommand constructor.
*
* @param JobQueue $queue
* @param MongoDriverInterface $mongoDriver
*/
public function __construct(JobQueue $queue, FailedJobProviderInterface $failer)
{
Expand All @@ -58,10 +55,7 @@ protected function configure()
/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
* @return int|void|null
*/
public function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -82,14 +76,12 @@ public function execute(InputInterface $input, OutputInterface $output)
}

$io->success(sprintf("[%d] job(s) has been released.\n", $jobsCount));

return 0;
}

/**
* Retry job
*
* @param Job $job
*
* @return bool
*/
protected function retryJob(Job $job): bool
{
Expand Down
9 changes: 3 additions & 6 deletions Command/RunJobCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class RunJobCommand extends Command

/**
* RunJobCommand constructor.
*
* @param LoggerInterface $logger
* @param Worker $worker
*/
public function __construct(Worker $worker)
Expand Down Expand Up @@ -55,10 +53,7 @@ protected function configure()
/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
* @return int|void|null
*/
public function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -73,5 +68,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$jobId = $input->getArgument('id');

$this->worker->runJobById($connection, $jobId, $options);

return 0;
}
}
9 changes: 3 additions & 6 deletions Command/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class WorkCommand extends Command

/**
* WorkCommand constructor.
*
* @param Worker $worker
*/
public function __construct(Worker $worker)
{
Expand Down Expand Up @@ -56,10 +54,7 @@ protected function configure()
/**
* Execute command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null|void
* @return int|void|null
*/
public function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -78,5 +73,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$io->success(sprintf('Worker daemon has started.'));

$this->worker->daemon($connection, $queue, $workerOptions);

return 0;
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/QueueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use SfCod\QueueBundle\Service\QueueManager;
use SfCod\QueueBundle\Worker\Worker;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -265,6 +264,7 @@ private function createJobProcess(array $config, ContainerBuilder $container)
$jobProcess->setArguments([
'console',
sprintf('%s/bin', $container->getParameter('kernel.project_dir')),
$container->getParameter('kernel.environment'),
]);

$container->setDefinition(JobProcess::class, $jobProcess);
Expand Down
2 changes: 1 addition & 1 deletion Event/JobExceptionOccurredEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;
use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobExceptionOccurredEvent
Expand Down
3 changes: 1 addition & 2 deletions Event/JobFailedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Exception;
use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobFailedEvent
Expand Down Expand Up @@ -43,7 +43,6 @@ class JobFailedEvent extends Event
* @param string $connectionName
* @param JobContractInterface $job
* @param Exception $exception
* @param array $config
*/
public function __construct(string $connectionName, JobContractInterface $job, Exception $exception)
{
Expand Down
3 changes: 1 addition & 2 deletions Event/JobProcessedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SfCod\QueueBundle\Event;

use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobProcessedEvent
Expand Down Expand Up @@ -34,7 +34,6 @@ class JobProcessedEvent extends Event
*
* @param string $connectionName
* @param JobContractInterface $job
* @param array $config
*/
public function __construct(string $connectionName, JobContractInterface $job)
{
Expand Down
3 changes: 1 addition & 2 deletions Event/JobProcessingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SfCod\QueueBundle\Event;

use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobProcessingEvent
Expand Down Expand Up @@ -34,7 +34,6 @@ class JobProcessingEvent extends Event
*
* @param string $connectionName
* @param JobContractInterface $job
* @param array $config
*/
public function __construct(string $connectionName, JobContractInterface $job)
{
Expand Down
2 changes: 1 addition & 1 deletion Event/WorkerStoppingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SfCod\QueueBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class WorkerStoppingEvent
Expand Down
54 changes: 23 additions & 31 deletions Service/JobProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,30 @@ class JobProcess
*/
public $binaryArgs;

/**
* @var string
*/
public $environment;

/**
* JobProcess constructor.
*
* @param string $scriptName
* @param string $binPath
* @param string $environment
* @param string $binary
* @param string $binaryArgs
*/
public function __construct(
string $scriptName,
string $binPath,
string $environment = 'prod',
string $binary = 'php',
string $binaryArgs = '')
{
$this->scriptName = $scriptName;
$this->binPath = $binPath;
$this->environment = $environment;
$this->binary = $binary;
$this->binaryArgs = $binaryArgs;
}
Expand All @@ -65,38 +73,22 @@ public function __construct(
*/
public function getProcess(JobContractInterface $job, Options $options): Process
{
$cmd = '%s %s job-queue:run-job %s --connection=%s --queue=%s --env=%s --delay=%s --memory=%s --timeout=%s --sleep=%s --maxTries=%s';
$cmd = $this->getBackgroundCommand($cmd);
$cmd = sprintf(
$cmd,
return new Process(array_filter([
defined('PHP_WINDOWS_VERSION_BUILD') ? 'start /B ' : null,
$this->getPhpBinary(),
$this->scriptName,
(string)$job->getJobId(),
$job->getConnectionName(),
$job->getQueue(),
getenv('APP_ENV'),
$options->delay,
$options->memory,
$options->timeout,
$options->sleep,
$options->maxTries
);

return new Process($cmd, $this->binPath);
}

/**
* @param $cmd
*
* @return string
*/
protected function getBackgroundCommand(string $cmd): string
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
return 'start /B ' . $cmd . ' > NUL';
} else {
return $cmd . ' > /dev/null 2>&1 &';
}
'job-queue:run-job',
$job->getJobId(),
'--connection=' . $job->getConnectionName(),
'--queue=' . $job->getQueue(),
'--env=' . $this->environment,
'--delay=' . $options->delay,
'--memory=' . $options->memory,
'--timeout=' . $options->timeout,
'--sleep=' . $options->sleep,
'--maxTries=' . $options->maxTries,
defined('PHP_WINDOWS_VERSION_BUILD') ? ' > NUL' : ' > /dev/null 2>&1 &',
]), $this->binPath);
}

/**
Expand All @@ -116,6 +108,6 @@ protected function getPhpBinary(): string
$args = implode(' ', $args);
}

return trim($path . ' ' . $args);
return trim(trim($path . ' ' . $args), '\'');
}
}
2 changes: 1 addition & 1 deletion Tests/Connector/MongoConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function testConnect()

$queue = $connector->connect($config);

$this->assertInstanceOf(MongoQueue::class, $queue);
self::assertInstanceOf(MongoQueue::class, $queue);
}
}
11 changes: 3 additions & 8 deletions Tests/Data/LoadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Dotenv\Exception\PathException;
use Symfony\Component\HttpKernel\HttpKernel;

/**
* Trait LoadTrait
Expand All @@ -30,16 +31,10 @@ trait LoadTrait
*/
protected function configure()
{
$dotenv = new Dotenv();
try {
$dotenv->load(__DIR__ . '/../../.env');
} catch (PathException $e) {
// Nothing
}

$extension = new QueueExtension();
$container = new ContainerBuilder();
$container->setParameter('kernel.project_dir', getenv('KERNEL_PROJECT_DIR'));
$container->setParameter('kernel.project_dir', '');
$container->setParameter('kernel.environment', 'prod');
$container->setParameter('kernel.root_dir', realpath(__DIR__ . '/../../../../SfCod/'));
$container->set(LoggerInterface::class, new Logger('test'));

Expand Down
12 changes: 6 additions & 6 deletions Tests/Entity/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public function testJob()
$job->setReservedAt($reservedAt);
$job->setPayload($payload);

$this->assertEquals($id, $job->getId());
$this->assertEquals($attempts, $job->getAttempts());
$this->assertEquals($queue, $job->getQueue());
$this->assertEquals($reserved, $job->isReserved());
$this->assertEquals($reservedAt, $job->getReservedAt());
$this->assertEquals($payload, $job->getPayload());
self::assertEquals($id, $job->getId());
self::assertEquals($attempts, $job->getAttempts());
self::assertEquals($queue, $job->getQueue());
self::assertEquals($reserved, $job->isReserved());
self::assertEquals($reservedAt, $job->getReservedAt());
self::assertEquals($payload, $job->getPayload());
}
}
12 changes: 6 additions & 6 deletions Tests/Event/JobExceptionOccurredEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PHPUnit\Framework\TestCase;
use SfCod\QueueBundle\Event\JobExceptionOccurredEvent;
use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobExceptionOccurredEventTest
Expand All @@ -29,10 +29,10 @@ public function testEvent()

$event = new JobExceptionOccurredEvent($connectionName, $job, $exception);

$this->assertInstanceOf(Event::class, $event);
$this->assertEquals($connectionName, $event->getConnectionName());
$this->assertEquals($job, $event->getJob());
$this->assertEquals($exception, $event->getException());
$this->assertEquals($exception->getMessage(), $event->getException()->getMessage());
self::assertInstanceOf(Event::class, $event);
self::assertEquals($connectionName, $event->getConnectionName());
self::assertEquals($job, $event->getJob());
self::assertEquals($exception, $event->getException());
self::assertEquals($exception->getMessage(), $event->getException()->getMessage());
}
}
12 changes: 6 additions & 6 deletions Tests/Event/JobFailedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use PHPUnit\Framework\TestCase;
use SfCod\QueueBundle\Event\JobFailedEvent;
use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobFailedEventTest
Expand All @@ -29,10 +29,10 @@ public function testEvent()

$event = new JobFailedEvent($connectionName, $job, $exception);

$this->assertInstanceOf(Event::class, $event);
$this->assertEquals($connectionName, $event->getConnectionName());
$this->assertEquals($job, $event->getJob());
$this->assertEquals($exception, $event->getException());
$this->assertEquals($exception->getMessage(), $event->getException()->getMessage());
self::assertInstanceOf(Event::class, $event);
self::assertEquals($connectionName, $event->getConnectionName());
self::assertEquals($job, $event->getJob());
self::assertEquals($exception, $event->getException());
self::assertEquals($exception->getMessage(), $event->getException()->getMessage());
}
}
8 changes: 4 additions & 4 deletions Tests/Event/JobProcessedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PHPUnit\Framework\TestCase;
use SfCod\QueueBundle\Event\JobProcessedEvent;
use SfCod\QueueBundle\Job\JobContractInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class JobProcessedEventTest
Expand All @@ -26,8 +26,8 @@ public function testEvent()

$event = new JobProcessedEvent($connectionName, $job);

$this->assertInstanceOf(Event::class, $event);
$this->assertEquals($connectionName, $event->getConnectionName());
$this->assertEquals($job, $event->getJob());
self::assertInstanceOf(Event::class, $event);
self::assertEquals($connectionName, $event->getConnectionName());
self::assertEquals($job, $event->getJob());
}
}
Loading

0 comments on commit c9cbf59

Please sign in to comment.