-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'schedulingmutex' of https://github.com/laurencei/framework
- Loading branch information
Showing
14 changed files
with
317 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Illuminate/Console/Scheduling/CacheSchedulingMutex.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Illuminate\Console\Scheduling; | ||
|
||
use Illuminate\Support\Carbon; | ||
use Illuminate\Contracts\Cache\Repository as Cache; | ||
|
||
class CacheSchedulingMutex implements SchedulingMutex | ||
{ | ||
/** | ||
* The cache repository implementation. | ||
* | ||
* @var \Illuminate\Contracts\Cache\Repository | ||
*/ | ||
public $cache; | ||
|
||
/** | ||
* Create a new overlapping strategy. | ||
* | ||
* @param \Illuminate\Contracts\Cache\Repository $cache | ||
* @return void | ||
*/ | ||
public function __construct(Cache $cache) | ||
{ | ||
$this->cache = $cache; | ||
} | ||
|
||
/** | ||
* Attempt to obtain a scheduling mutex for the given event. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Event $event | ||
* @param \Illuminate\Support\Carbon $time | ||
* @return bool | ||
*/ | ||
public function create(Event $event, Carbon $time) | ||
{ | ||
return $this->cache->add( | ||
$event->mutexName().$time->format('Hi'), true, 60 | ||
); | ||
} | ||
|
||
/** | ||
* Determine if a scheduling mutex exists for the given event. | ||
* | ||
* @param \Illuminate\Console\Scheduling\Event $event | ||
* @param \Illuminate\Support\Carbon $time | ||
* @return bool | ||
*/ | ||
public function exists(Event $event, Carbon $time) | ||
{ | ||
return $this->cache->has($event->mutexName().$time->format('Hi')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.