Skip to content

Commit

Permalink
Merge pull request #40 from Indatus/develop
Browse files Browse the repository at this point in the history
Resolved issues with $scheduler instance used within multiple commands
  • Loading branch information
bkuhl committed May 15, 2014
2 parents 6bfe711 + 52d6bf9 commit 926ed1f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function user();
/**
* When a command should run
* @param Scheduler $scheduler
* @return \Indatus\Dispatcher\Scheduling\Schedulable
* @return \Indatus\Dispatcher\Scheduling\Schedulable|\Indatus\Dispatcher\Scheduling\Schedulable[]
*/
public function schedule(Schedulable $scheduler);

Expand Down
1 change: 1 addition & 0 deletions src/Indatus/Dispatcher/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function boot()
*/
public function register()
{
/** @var \Indatus\Dispatcher\ConfigResolver $resolver */
$resolver = App::make('\Indatus\Dispatcher\ConfigResolver');

//load the scheduler of the appropriate driver
Expand Down
11 changes: 6 additions & 5 deletions src/Indatus/Dispatcher/Services/ScheduleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract public function isDue(Schedulable $scheduler);
/**
* Get all commands that are scheduled
*
* @return array
* @return \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface[]
*/
public function getScheduledCommands()
{
Expand All @@ -64,17 +64,18 @@ public function getQueue()
/** @var \Indatus\Dispatcher\Queue $queue */
$queue = App::make('Indatus\Dispatcher\Queue');

/** @var \Indatus\Dispatcher\Scheduling\Schedulable $scheduler */
$scheduler = App::make('Indatus\Dispatcher\Scheduling\Schedulable');

/** @var \Indatus\Dispatcher\Scheduling\ScheduledCommandInterface $command */
foreach ($this->getScheduledCommands() as $command) {

/** @var \Indatus\Dispatcher\Scheduling\Schedulable $scheduler */
$scheduler = App::make('Indatus\Dispatcher\Scheduling\Schedulable');

//could be multiple schedules based on arguments
$schedules = $command->schedule($scheduler);
if (!is_array($schedules)) {
$schedules = array($schedules);
}

//echo $command->getName()." (".count($schedules).")\n";
foreach ($schedules as $schedule) {
if (($schedule instanceOf Schedulable) === false) {
throw new \InvalidArgumentException('Schedule for "'.$command->getName().'" is not an instance of Schedulable');
Expand Down

0 comments on commit 926ed1f

Please sign in to comment.