diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..2fc4351 --- /dev/null +++ b/changelog.md @@ -0,0 +1,15 @@ +# Changelog + +All notable changes will be documented in this file. + +## 0.2.0 6/3/2020 + +### Added +- Add `daemonize()` macro to `Event` + +### Changed + +### Fixed + +## 0.0.1 - 5/17/2020 +- Initial release \ No newline at end of file diff --git a/composer.json b/composer.json index 4695903..efb4687 100644 --- a/composer.json +++ b/composer.json @@ -26,5 +26,12 @@ "psr-4": { "Resolute\\PseudoDaemon\\Tests\\": "tests/" } + }, + "extra": { + "laravel": { + "providers": [ + "Resolute\\PseudoDaemon\\PseudoDaemonServiceProvider" + ] + } } } diff --git a/src/PseudoDaemonServiceProvider.php b/src/PseudoDaemonServiceProvider.php new file mode 100644 index 0000000..c5839d6 --- /dev/null +++ b/src/PseudoDaemonServiceProvider.php @@ -0,0 +1,24 @@ + + */ + +namespace Resolute\PseudoDaemon; + +use Illuminate\Console\Scheduling\CallbackEvent; +use Illuminate\Console\Scheduling\Event; +use Illuminate\Support\ServiceProvider; + +class PseudoDaemonServiceProvider extends ServiceProvider +{ + public function register() + { + Event::macro('daemonize', function () { + if ($this instanceof CallbackEvent) { + throw new \Exception('Cannot daemonize a CallbackEvent.'); + } + + return $this->everyMinute()->runInBackground()->withoutOverlapping(); + }); + } +} \ No newline at end of file diff --git a/tests/EventDaemonizeTest.php b/tests/EventDaemonizeTest.php new file mode 100644 index 0000000..e5884a0 --- /dev/null +++ b/tests/EventDaemonizeTest.php @@ -0,0 +1,32 @@ + + */ + +namespace Resolute\PseudoDaemon\Tests; + +use Illuminate\Console\Scheduling\CacheEventMutex; +use Illuminate\Console\Scheduling\Event; +use Orchestra\Testbench\TestCase; +use Resolute\PseudoDaemon\PseudoDaemonServiceProvider; + +class EventDaemonizeTest extends TestCase +{ + protected function getPackageProviders($app) + { + return [ + PseudoDaemonServiceProvider::class + ]; + } + + /** @test */ + public function daemonize_macro_sets_appropriate_properties() + { + $mutex = new CacheEventMutex(cache()); + $event = (new Event($mutex, 'command'))->daemonize(); + + $this->assertTrue($event->runInBackground); + $this->assertTrue($event->withoutOverlapping); + $this->assertEquals('* * * * *', $event->expression); + } +} \ No newline at end of file