Skip to content

Commit

Permalink
[11.x] Introduce Schedule Grouping (#53427)
Browse files Browse the repository at this point in the history
* Add ability to group schedules

* Add missing native types

* Add missing event filters

* fix: cs

* add missing docblocks

* fix cs

* re-implement

* cs

* fix styleci

* add missing docblocks

* refactor code spacing

Co-authored-by: Steve Bauman <steven_bauman@outlook.com>

* fix styleci error

* formatting

* add files

* rename method'

---------

Co-authored-by: Steve Bauman <steven_bauman@outlook.com>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
3 people authored Nov 15, 2024
1 parent 29907b2 commit bab8683
Show file tree
Hide file tree
Showing 5 changed files with 485 additions and 198 deletions.
198 changes: 1 addition & 197 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Reflector;
use Illuminate\Support\Stringable;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\ReflectsClosures;
Expand All @@ -23,7 +22,7 @@

class Event
{
use Macroable, ManagesFrequencies, ReflectsClosures, Tappable;
use Macroable, ManagesAttributes, ManagesFrequencies, ReflectsClosures, Tappable;

/**
* The command string.
Expand All @@ -32,90 +31,6 @@ class Event
*/
public $command;

/**
* The cron expression representing the event's frequency.
*
* @var string
*/
public $expression = '* * * * *';

/**
* How often to repeat the event during a minute.
*
* @var int|null
*/
public $repeatSeconds = null;

/**
* The timezone the date should be evaluated on.
*
* @var \DateTimeZone|string
*/
public $timezone;

/**
* The user the command should run as.
*
* @var string|null
*/
public $user;

/**
* The list of environments the command should run under.
*
* @var array
*/
public $environments = [];

/**
* Indicates if the command should run in maintenance mode.
*
* @var bool
*/
public $evenInMaintenanceMode = false;

/**
* Indicates if the command should not overlap itself.
*
* @var bool
*/
public $withoutOverlapping = false;

/**
* Indicates if the command should only be allowed to run on one server for each cron expression.
*
* @var bool
*/
public $onOneServer = false;

/**
* The number of minutes the mutex should be valid.
*
* @var int
*/
public $expiresAt = 1440;

/**
* Indicates if the command should run in the background.
*
* @var bool
*/
public $runInBackground = false;

/**
* The array of filter callbacks.
*
* @var array
*/
protected $filters = [];

/**
* The array of reject callbacks.
*
* @var array
*/
protected $rejects = [];

/**
* The location that output should be sent to.
*
Expand Down Expand Up @@ -666,117 +581,6 @@ protected function getHttpClient(Container $container)
};
}

/**
* State that the command should run in the background.
*
* @return $this
*/
public function runInBackground()
{
$this->runInBackground = true;

return $this;
}

/**
* Set which user the command should run as.
*
* @param string $user
* @return $this
*/
public function user($user)
{
$this->user = $user;

return $this;
}

/**
* Limit the environments the command should run in.
*
* @param array|mixed $environments
* @return $this
*/
public function environments($environments)
{
$this->environments = is_array($environments) ? $environments : func_get_args();

return $this;
}

/**
* State that the command should run even in maintenance mode.
*
* @return $this
*/
public function evenInMaintenanceMode()
{
$this->evenInMaintenanceMode = true;

return $this;
}

/**
* Do not allow the event to overlap each other.
*
* The expiration time of the underlying cache lock may be specified in minutes.
*
* @param int $expiresAt
* @return $this
*/
public function withoutOverlapping($expiresAt = 1440)
{
$this->withoutOverlapping = true;

$this->expiresAt = $expiresAt;

return $this->skip(function () {
return $this->mutex->exists($this);
});
}

/**
* Allow the event to only run on one server for each cron expression.
*
* @return $this
*/
public function onOneServer()
{
$this->onOneServer = true;

return $this;
}

/**
* Register a callback to further filter the schedule.
*
* @param \Closure|bool $callback
* @return $this
*/
public function when($callback)
{
$this->filters[] = Reflector::isCallable($callback) ? $callback : function () use ($callback) {
return $callback;
};

return $this;
}

/**
* Register a callback to further filter the schedule.
*
* @param \Closure|bool $callback
* @return $this
*/
public function skip($callback)
{
$this->rejects[] = Reflector::isCallable($callback) ? $callback : function () use ($callback) {
return $callback;
};

return $this;
}

/**
* Register a callback to be called before the operation.
*
Expand Down
Loading

0 comments on commit bab8683

Please sign in to comment.