Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Command/ClearQueueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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 Command::SUCCESS;
}
Expand Down
36 changes: 18 additions & 18 deletions Command/StartScheduledWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,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 @@ -58,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 @@ -96,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 @@ -127,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 Down
30 changes: 15 additions & 15 deletions Command/StartWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}

$env['APP_INCLUDE'] = $this->params->get('resque.app_include');
$env['APP_INCLUDE'] = $this->params->get('resque.app_include');
$env['COUNT'] = $input->getOption('count');
$env['INTERVAL'] = $input->getOption('interval');
$env['QUEUE'] = $input->getArgument('queues');

// Allow Sentry.io integration
if ($this->params->has('sentry.dsn')) {
if ($sentryDSN = $this->params->get('sentry.dsn')) {
$output->writeln('Enabling Sentry Reporting to DSN '.$sentryDSN);
if ($sentryDSN = $this->params->get('sentry.dsn')) {
$output->writeln('Enabling Sentry Reporting to DSN ' . $sentryDSN);
$env['SENTRY_DSN'] = $sentryDSN;
}
}
Expand All @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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');
}

if ($input->getOption('verbose')) {
Expand All @@ -92,13 +92,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
unset($env['VERBOSE']);
}

$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 @@ -110,14 +110,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$opt = '';
if (0 !== $m = (int) $input->getOption('memory-limit')) {
if (0 !== $m = (int)$input->getOption('memory-limit')) {
$opt = sprintf('-d memory_limit=%dM', $m);
}

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';
}
Expand All @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$workerCommand = strtr('%php% %opt% %dir%/resque', [
'%php%' => $phpExecutable,
'%opt%' => $opt,
'%dir%' => __DIR__.'/../bin',
'%dir%' => __DIR__ . '/../bin',
]);

if (!$input->getOption('foreground')) {
Expand All @@ -141,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// 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 @@ -154,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// if foreground, we redirect output
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 Down
4 changes: 2 additions & 2 deletions Command/StopScheduledWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
*/
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)) {
$output->writeln('No PID file found');
Expand All @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$pid = file_get_contents($pidFile);

$output->writeln('Killing process '.$pid);
$output->writeln('Killing process ' . $pid);

posix_kill($pid, SIGKILL);

Expand Down
6 changes: 3 additions & 3 deletions ContainerAwareJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ protected function getContainer()
protected function createKernel()
{
$finder = new Finder();
$finder->name('*Kernel.php')->depth('<=1')->in($this->args['kernel.project_dir'].'/src');
$finder->name('*Kernel.php')->depth('<=1')->in($this->args['kernel.project_dir'] . '/src');
$results = iterator_to_array($finder);
$file = current($results);
$class = $file->getBasename('.php');

// Take into account any namespace
preg_match('/namespace\s(.*)\;/', file_get_contents($file), $matches);
if (2 == \count($matches)) {
$namespace = '\\'.$matches[1].'\\';
$class = $namespace.$class;
$namespace = '\\' . $matches[1] . '\\';
$class = $namespace . $class;
}

require_once $file;
Expand Down
8 changes: 4 additions & 4 deletions Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function removeQueueAction($queue, Request $request)
$count = $queue->clear();
$queue->remove();

$this->addFlash('info', 'Remove '.$queue->getName().' queue and '.$count.' jobs.');
$this->addFlash('info', 'Remove ' . $queue->getName() . ' queue and ' . $count . ' jobs.');

return $this->redirectToRoute('ResqueBundle_homepage');
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public function retryFailedAction()
{
$count = $this->resque->retryFailedJobs();

$this->addFlash('info', 'Retry '.$count.' failed jobs.');
$this->addFlash('info', 'Retry ' . $count . ' failed jobs.');

return $this->redirectToRoute('ResqueBundle_homepage');
}
Expand All @@ -195,7 +195,7 @@ public function retryClearFailedAction()
{
$count = $this->resque->retryFailedJobs(true);

$this->addFlash('info', 'Retry and clear '.$count.' failed jobs.');
$this->addFlash('info', 'Retry and clear ' . $count . ' failed jobs.');

return $this->redirectToRoute('ResqueBundle_homepage');
}
Expand All @@ -207,7 +207,7 @@ public function clearFailedAction()
{
$count = $this->resque->clearFailedJobs();

$this->addFlash('info', 'Clear '.$count.' failed jobs.');
$this->addFlash('info', 'Clear ' . $count . ' failed jobs.');

return $this->redirectToRoute('ResqueBundle_homepage');
}
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getConfigTreeBuilder()

if (method_exists($treeBuilder, 'getRootNode')) {
// Symfony 4+
$root = $treeBuilder->getRootNode();
$root = $treeBuilder->getRootNode();
} else {
// Symfony 3
$root = $treeBuilder->root('resque');
Expand Down Expand Up @@ -56,7 +56,7 @@ public function getConfigTreeBuilder()
->arrayNode('auto_retry')
->beforeNormalization()
->ifArray()
->then(function ($var) {
->then(function($var) {
if (\array_key_exists(0, $var)) {
return [$var];
}
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/ResqueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

$container->setParameter('resque.vendor_dir', $config['vendor_dir']);
Expand Down
6 changes: 3 additions & 3 deletions Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getName()
*/
public function getJobs($start = 0, $stop = -1)
{
$jobs = \Resque::redis()->lrange('queue:'.$this->name, $start, $stop);
$jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);

$result = [];
foreach ($jobs as $job) {
Expand All @@ -68,8 +68,8 @@ public function remove()
*/
public function clear()
{
$length = \Resque::redis()->llen('queue:'.$this->name);
\Resque::redis()->del('queue:'.$this->name);
$length = \Resque::redis()->llen('queue:' . $this->name);
\Resque::redis()->del('queue:' . $this->name);

return $length;
}
Expand Down
12 changes: 6 additions & 6 deletions Resque.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setRedisConfiguration($host, $port, $database, $password = null)
];

if (!isset($password)) {
\Resque::setBackend($host.':'.$port, $database);
\Resque::setBackend($host . ':' . $port, $database);
} else {
$server = 'redis://:' . $password . '@' . $host . ':' . $port;
\Resque::setBackend($server, $database);
Expand Down Expand Up @@ -263,7 +263,7 @@ public function removeFromTimestamp($at, Job $job)
*/
public function getQueues()
{
return array_map(function ($queue) {
return array_map(function($queue) {
return new Queue($queue);
}, \Resque::queues());
}
Expand All @@ -283,7 +283,7 @@ public function getQueue($queue)
*/
public function getWorkers()
{
return array_map(function ($worker) {
return array_map(function($worker) {
return new Worker($worker);
}, \Resque_Worker::all());
}
Expand All @@ -293,7 +293,7 @@ public function getWorkers()
*/
public function getRunningWorkers()
{
return array_filter($this->getWorkers(), function (Worker $worker) {
return array_filter($this->getWorkers(), function(Worker $worker) {
return null !== $worker->getCurrentJob();
});
}
Expand Down Expand Up @@ -370,7 +370,7 @@ public function getDelayedJobTimestamps()
//TODO: find a more efficient way to do this
$out = [];
foreach ($timestamps as $timestamp) {
$out[] = [$timestamp, \Resque::redis()->llen('delayed:'.$timestamp)];
$out[] = [$timestamp, \Resque::redis()->llen('delayed:' . $timestamp)];
}

return $out;
Expand All @@ -391,7 +391,7 @@ public function getNumberOfDelayedJobs()
*/
public function getJobsForTimestamp($timestamp)
{
$jobs = \Resque::redis()->lrange('delayed:'.$timestamp, 0, -1);
$jobs = \Resque::redis()->lrange('delayed:' . $timestamp, 0, -1);
$out = [];
foreach ($jobs as $job) {
$out[] = json_decode($job, true);
Expand Down
4 changes: 2 additions & 2 deletions Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function stop()
*/
public function getId()
{
return (string) $this->worker;
return (string)$this->worker;
}

/**
* @return array
*/
public function getQueues()
{
return array_map(function ($queue) {
return array_map(function($queue) {
return new Queue($queue);
}, $this->worker->queues());
}
Expand Down