Skip to content

Commit

Permalink
Merge remote-tracking branch 'betom84/update_laravel'
Browse files Browse the repository at this point in the history
  • Loading branch information
tback committed Dec 5, 2017
2 parents 9f99061 + 57cc8e5 commit d185604
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
Provides a single artisan command to run `schedule:run` as a daemon. Use this if, and only if you can guarantee that all your `schedule:run` executions will terminate in 60 seconds or less. This should be easy if you use `schedule:run` only to dispatch scheduled jobs to workers. Events might me dropped in case the runs take longer to finish.

## Installation
This package requires at least Laravel 5.5.
Install via composer:
```
composer require tback/scheduledaemon
```

Then add ServiceProvider to `config/app.php`:
Laravels package auto-discovery feature is supported, so nothing more to do.
You may add ServiceProvider manually by editing `config/app.php`:
```
...
$providers => [
Expand Down
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "tback/scheduledaemon",
"description": "ScheduleDaemon for Laravel. You must ensure every schedule:run is shorter then 60 seconds otherwise events might be ignored.",
"type": "library",
"keywords": ["laravel"],
"keywords": [
"laravel"
],
"require": {
"illuminate/support": "^5.3",
"illuminate/console": "^5.3",
"symfony/console": "^3.1"
"illuminate/support": "^5.5",
"illuminate/console": "^5.5"
},
"license": "MIT",
"authors": [
Expand All @@ -19,5 +20,12 @@
"psr-4": {
"ScheduleDaemon\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"ScheduleDaemon\\ServiceProvider"
]
}
}
}
}
8 changes: 5 additions & 3 deletions src/ScheduleDaemonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ class ScheduleDaemonCommand extends Command
*
* @return void
*/
public function fire()
public function handle()
{
while (true) {
$start = time();
$this->call('schedule:run');

$sleepTime = max(0, self::SCHEDULE_INTERVAL - (time() - $start));
if (0 == $sleepTime) {
$this->error(sprintf('schedule:run did not finish in %d seconds. Some events might have been skipped.',
self::SCHEDULE_INTERVAL));
$this->error(sprintf(
'schedule:run did not finish in %d seconds. Some events might have been skipped.',
self::SCHEDULE_INTERVAL
));
}
sleep($sleepTime);
}
Expand Down

0 comments on commit d185604

Please sign in to comment.