Skip to content

Commit

Permalink
Add daemonize
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Jun 3, 2020
1 parent fd378a6 commit 032c691
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
15 changes: 15 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@
"psr-4": {
"Resolute\\PseudoDaemon\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Resolute\\PseudoDaemon\\PseudoDaemonServiceProvider"
]
}
}
}
24 changes: 24 additions & 0 deletions src/PseudoDaemonServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @author Aaron Francis <[email protected]|https://twitter.com/aarondfrancis>
*/

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();
});
}
}
32 changes: 32 additions & 0 deletions tests/EventDaemonizeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @author Aaron Francis <[email protected]|https://twitter.com/aarondfrancis>
*/

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);
}
}

0 comments on commit 032c691

Please sign in to comment.