Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

26 changes: 10 additions & 16 deletions Command/CleanUpWorkersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,23 @@

namespace ResqueBundle\Resque\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use ResqueBundle\Resque\Resque;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class CleanUpWorkersCommand.
*/
#[AsCommand(
name: 'resque:cleanup:workers',
description: 'Unregisters all workers in Redis. Workers may need to be restarted.',
)]
class CleanUpWorkersCommand extends Command
{
private $resque;

public function __construct(string $name = null, Resque $resque)
{
$this->resque = $resque;
parent::__construct($name);
}

protected function configure()
public function __construct(
private Resque $resque
)
{
$this
->setName('resque:cleanup:workers')
->setDescription('Unregisters all workers in Redis. Workers may need to be restarted.');
parent::__construct();
}

/**
Expand All @@ -50,6 +44,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

return 0;
return Command::SUCCESS;
}
}
25 changes: 11 additions & 14 deletions Command/ClearQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,28 @@

namespace ResqueBundle\Resque\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use ResqueBundle\Resque\Resque;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class ClearQueueCommand.
*/
#[AsCommand(
name: 'resque:clear-queue',
description: 'Clear a resque queue',
)]
class ClearQueueCommand extends Command
{
private $resque;

public function __construct(string $name = null, Resque $resque)
public function __construct(
private Resque $resque)
{
$this->resque = $resque;
parent::__construct($name);
parent::__construct();
}

protected function configure()
{
$this
->setName('resque:clear-queue')
->setDescription('Clear a resque queue')
->addArgument('queue', InputArgument::REQUIRED, 'Queue name');
$this->addArgument('queue', InputArgument::REQUIRED, 'Queue name');
}

/**
Expand All @@ -46,8 +43,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$queue = $input->getArgument('queue');
$count = $this->resque->clearQueue($queue);

$output->writeln('Cleared queue '.$queue.' - removed '.$count.' entries');
$output->writeln('Cleared queue ' . $queue . ' - removed ' . $count . ' entries');

return 0;
return Command::SUCCESS;
}
}
26 changes: 10 additions & 16 deletions Command/PingTestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@

namespace ResqueBundle\Resque\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use ResqueBundle\Resque\ExampleJobs\PingJob;
use ResqueBundle\Resque\Resque;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class PingTestCommand.
*/
#[AsCommand(
name: 'resque:pingtest',
description: 'Send a Ping as a test, and let a job reply with pong',
)]
class PingTestCommand extends Command
{
private $resque;

public function __construct(string $name = null, Resque $resque)
{
$this->resque = $resque;
parent::__construct($name);
}

protected function configure()
public function __construct(
private Resque $resque
)
{
$this
->setName('resque:pingtest')
->setDescription('Send a Ping as a test, and let a job reply with pong');
parent::__construct();
}

/**
Expand All @@ -45,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$job = new PingJob();
$output->writeln($this->resque->enqueue($job, true));

return 0;
return Command::SUCCESS;
}
}
56 changes: 27 additions & 29 deletions Command/StartScheduledWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@

namespace ResqueBundle\Resque\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Process\Process;

/**
* Class StartScheduledWorkerCommand.
*/
#[AsCommand(
name: 'resque:scheduledworker-start',
description: 'Start a scheduled resque worker',
)]
class StartScheduledWorkerCommand extends Command
{
private $params;

public function __construct(string $name = null, ParameterBagInterface $params)
public function __construct(
private ParameterBagInterface $params)
{
$this->params = $params;
parent::__construct($name);
parent::__construct();
}

protected function configure()
{
$this
->setName('resque:scheduledworker-start')
->setDescription('Start a scheduled resque worker')
->addOption('foreground', 'f', InputOption::VALUE_NONE, 'Should the worker run in foreground')
->addOption('force', null, InputOption::VALUE_NONE, 'Force creation of a new worker if the PID file exists')
->addOption('interval', 'i', InputOption::VALUE_REQUIRED, 'How often to check for new jobs across the queues', 5);
Expand All @@ -48,7 +46,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$pidFile = $this->params->get('kernel.cache_dir').'/resque_scheduledworker.pid';
$pidFile = $this->params->get('kernel.cache_dir') . '/resque_scheduledworker.pid';
if (file_exists($pidFile) && !$input->getOption('force')) {
throw new \Exception('PID file exists - use --force to override');
}
Expand All @@ -60,31 +58,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
$env = [
'APP_INCLUDE' => $this->params->get('resque.app_include'),
'VVERBOSE' => 1,
'RESQUE_PHP' => $this->params->get('resque.vendor_dir').'/chrisboulton/php-resque/lib/Resque.php',
'RESQUE_PHP' => $this->params->get('resque.vendor_dir') . '/chrisboulton/php-resque/lib/Resque.php',
'INTERVAL' => $input->getOption('interval'),
];

if (!file_exists($env['RESQUE_PHP'])) {
$env['RESQUE_PHP'] = $this->params->get('resque.vendor_dir').'/resque/php-resque/lib/Resque.php';
$env['RESQUE_PHP'] = $this->params->get('resque.vendor_dir') . '/resque/php-resque/lib/Resque.php';
}

if (false !== getenv('APP_INCLUDE')) {
$env['APP_INCLUDE'] = getenv('APP_INCLUDE');
}

$prefix = $this->params->get('resque.prefix');
$prefix = $this->params->get('resque.prefix');

if (!empty($prefix)) {
$env['PREFIX'] = $this->params->get('resque.prefix');
$env['PREFIX'] = $this->params->get('resque.prefix');
}

$redisHost = $this->params->get('resque.redis.host');
$redisPort = $this->params->get('resque.redis.port');
$redisDatabase = $this->params->get('resque.redis.database');
$redisPassword = $this->params->get('resque.redis.password');
$redisHost = $this->params->get('resque.redis.host');
$redisPort = $this->params->get('resque.redis.port');
$redisDatabase = $this->params->get('resque.redis.database');
$redisPassword = $this->params->get('resque.redis.password');

if (null != $redisHost && null != $redisPort) {
$env['REDIS_BACKEND'] = $redisHost.':'.$redisPort;
$env['REDIS_BACKEND'] = $redisHost . ':' . $redisPort;
}

if (isset($redisDatabase)) {
Expand All @@ -98,28 +96,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
$phpExecutable = PHP_BINARY;
} else {
$phpExecutable = PHP_BINDIR.'/php';
$phpExecutable = PHP_BINDIR . '/php';
if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
$phpExecutable = 'php';
}
}

$workdirectory = __DIR__.'/../bin/';
$workerCommand = $phpExecutable.' '.$workdirectory.'resque-scheduler';
$workdirectory = __DIR__ . '/../bin/';
$workerCommand = $phpExecutable . ' ' . $workdirectory . 'resque-scheduler';

if (!$input->getOption('foreground')) {
$logFile = $this->params->get(
$logFile = $this->params->get(
'kernel.logs_dir'
).'/resque-scheduler_'.$this->params->get('kernel.environment').'.log';
$workerCommand = 'nohup '.$workerCommand.' > '.$logFile.' 2>&1 & echo $!';
) . '/resque-scheduler_' . $this->params->get('kernel.environment') . '.log';
$workerCommand = 'nohup ' . $workerCommand . ' > ' . $logFile . ' 2>&1 & echo $!';
}

// In windows: When you pass an environment to CMD it replaces the old environment
// That means we create a lot of problems with respect to user accounts and missing vars
// this is a workaround where we add the vars to the existing environment.
if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
foreach ($env as $key => $value) {
putenv($key.'='.$value);
putenv($key . '=' . $value);
}
$env = null;
}
Expand All @@ -129,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln(sprintf('Starting worker <info>%s</info>', $process->getCommandLine()));

if ($input->getOption('foreground')) {
$process->run(function ($type, $buffer) use ($output) {
$process->run(function($type, $buffer) use ($output) {
$output->write($buffer);
});
} // else we recompose and display the worker id
Expand All @@ -145,6 +143,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
file_put_contents($pidFile, $pid);
}

return 0;
return Command::SUCCESS;
}
}
Loading