Skip to content

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbojsb committed Jan 4, 2013
1 parent 6b7f5bb commit ec92b64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions lib/Bstools/App.php
Expand Up @@ -19,5 +19,6 @@ public function __construct()
$this->add(new \Bstools\Command\Drain());
$this->add(new \Bstools\Command\Peek());
$this->add(new \Bstools\Command\Bury());
$this->add(new \Bstools\Command\StatsJob());
}
}
15 changes: 8 additions & 7 deletions lib/Bstools/Command/Peek.php
Expand Up @@ -14,21 +14,22 @@ public function configure()
$this->setName('peek')
->setDescription('Peek at the job on top of the ready or buried queue');
$this->addArgument('tube', InputArgument::REQUIRED, 'the tube to drain from');
$this->addOption('buried', null, InputOption::VALUE_NONE, 'drain from buried instead of ready');
$this->addArgument('state', InputArgument::OPTIONAL, 'peek from buried instead of ready', 'ready');
}

public function execute(InputInterface $input, OutputInterface $output)
{
$pheanstalk = new \Pheanstalk($input->getOption('host'));

$tube = $input->getArgument('tube');
$buried = $input->getOption('buried');
$state = $input->getArgument('state');
$permissibleStates = array('ready', 'buried', 'delayed');
if (!in_array($state, $permissibleStates)) {
throw new \Exception("$state is not a valid job state");
}
try {
if ($buried) {
$job = $pheanstalk->peekBuried($tube);
} else {
$job = $pheanstalk->peekReady($tube);
}
$cmd = "peek" . ucfirst(strtolower($state));
$job = $pheanstalk->$cmd($tube);
} catch (\Exception $e) {
return;
}
Expand Down

0 comments on commit ec92b64

Please sign in to comment.