diff --git a/README.md b/README.md index a82f1df..305b8b2 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,16 @@ Simply `extend \Indatus\Dispatcher\ScheduledCommand` and implement the `schedule } ``` +You may also schedule commands via raw cron expressions + +```php + public function schedule(Schedulable $scheduler) + { + //every other day at 3:15am, 4:15am and 5:15am + return $scheduler->setSchedule(3, [3,4,5], '*/2', '*', '*'); + } +``` + ### Running Commands As Users diff --git a/src/Indatus/Dispatcher/Drivers/Cron/Scheduler.php b/src/Indatus/Dispatcher/Drivers/Cron/Scheduler.php index 90bdc39..7bf2f9b 100644 --- a/src/Indatus/Dispatcher/Drivers/Cron/Scheduler.php +++ b/src/Indatus/Dispatcher/Drivers/Cron/Scheduler.php @@ -71,6 +71,7 @@ public function getSchedule() * @param mixed $dayOfMonth * @param mixed $month * @param mixed $dayOfWeek + * @return $this */ public function setSchedule($minute, $hour, $dayOfMonth, $month, $dayOfWeek) { @@ -85,6 +86,8 @@ public function setSchedule($minute, $hour, $dayOfMonth, $month, $dayOfWeek) $this->setScheduleDayOfMonth($dayOfMonth); $this->setScheduleMonth($month); $this->setScheduleDayOfWeek($dayOfWeek); + + return $this; } /** diff --git a/src/Indatus/Dispatcher/Schedulable.php b/src/Indatus/Dispatcher/Schedulable.php index 678dd71..a1943ba 100644 --- a/src/Indatus/Dispatcher/Schedulable.php +++ b/src/Indatus/Dispatcher/Schedulable.php @@ -54,6 +54,7 @@ public function daysOfTheMonth($hoursIntoTheDay); * @param mixed $dayOfMonth * @param mixed $month * @param mixed $dayOfWeek + * @return $this */ public function setSchedule($minute, $hour, $dayOfMonth, $month, $dayOfWeek); diff --git a/tests/Drivers/Cron/TestCronScheduler.php b/tests/Drivers/Cron/TestCronScheduler.php index fda84e3..324b7d7 100644 --- a/tests/Drivers/Cron/TestCronScheduler.php +++ b/tests/Drivers/Cron/TestCronScheduler.php @@ -30,7 +30,7 @@ public function testBuildingSchedule() public function testSetSchedule() { - $this->scheduler->setSchedule(1, 2, 3, 4, 5); + $this->assertInstanceOf($this->schedularClass, $this->scheduler->setSchedule(1, 2, 3, 4, 5)); $this->assertEquals($this->scheduler->getSchedule(), '1 2 3 4 5'); }