Skip to content

Commit

Permalink
Clean up commands and move to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilETaylor committed Sep 6, 2021
1 parent 45de899 commit 8777fa9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 87 deletions.
24 changes: 9 additions & 15 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 Down
21 changes: 9 additions & 12 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 Down
24 changes: 9 additions & 15 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 Down
18 changes: 8 additions & 10 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 Down
18 changes: 8 additions & 10 deletions Command/StartWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace ResqueBundle\Resque\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -16,24 +17,21 @@
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Process\Process;

/**
* Class StartWorkerCommand.
*/
#[AsCommand(
name: 'resque:worker-start',
description: 'Start a resque worker',
)]
class StartWorkerCommand 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:worker-start')
->setDescription('Start a resque worker')
->addArgument('queues', InputArgument::REQUIRED, 'Queue names (separate using comma)')
->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many workers to fork', 1)
->addOption('interval', 'i', InputOption::VALUE_REQUIRED, 'How often to check for new jobs across the queues', 5)
Expand Down
23 changes: 8 additions & 15 deletions Command/StopScheduledWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,22 @@

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\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

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

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

protected function configure()
public function __construct(
private ParameterBagInterface $params)
{
$this
->setName('resque:scheduledworker-stop')
->setDescription('Stop a resque scheduled worker');
parent::__construct();
}

/**
Expand Down
18 changes: 8 additions & 10 deletions Command/StopWorkerCommand.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 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\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class StopWorkerCommand.
*/
#[AsCommand(
name: 'resque:worker-stop',
description: 'Stop a resque worker',
)]
class StopWorkerCommand 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:worker-stop')
->setDescription('Stop a resque worker')
->addArgument('id', InputArgument::OPTIONAL, 'Worker id')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Should kill all workers');
}
Expand Down

0 comments on commit 8777fa9

Please sign in to comment.