-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store schedule monitoring configurations in its own singleton #114
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f418e6a
Store schedule monitoring configurations in its own singleton
m-bymike eed204f
Trigger CI
freekmurze 1a94f91
Refactor schedule monitoring repository usage.
m-bymike aae12a0
Merge branch 'spatie:main' into main
m-bymike 906c3bc
Rename `getScheduleMonitoringConfigurationsRepository` to `getMonitor…
m-bymike 534e4e0
Use the monitored scheduled tasks to retrieve the flag
m-bymike 00045a4
Update test to use dynamic environment configuration
m-bymike 3811a44
Update test suite to use PHP 8.4 and 8.3, discard 8.0
m-bymike f0298c0
Discard EoL PHP 8.1
m-bymike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,13 @@ | ||
<?php | ||
|
||
namespace Spatie\ScheduleMonitor\Support\Concerns; | ||
|
||
use Spatie\ScheduleMonitor\Support\ScheduledTasks\MonitoredScheduledTasks; | ||
|
||
trait UsesMonitoredScheduledTasks | ||
{ | ||
public function getScheduleMonitoringConfigurationsRepository(): MonitoredScheduledTasks | ||
{ | ||
return app(MonitoredScheduledTasks::class); | ||
} | ||
} |
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,91 @@ | ||
<?php | ||
|
||
namespace Spatie\ScheduleMonitor\Support\ScheduledTasks; | ||
|
||
class MonitoredScheduledTasks | ||
{ | ||
/** | ||
* Multidimensional array to hold values grouped by class, instance id and property. | ||
* | ||
* Example: | ||
* | ||
* ``` | ||
* [ '\Illuminate\Console\Scheduling\Event' => 'obj_234' => [ 'propertyName' => 'some_value' ]]] | ||
* ``` | ||
* | ||
* @see self::makeKey() | ||
* | ||
* @var array<string,array<string,array<string,mixed>>> | ||
*/ | ||
protected array $store = []; | ||
|
||
public function setMonitorName(object $target, string $monitorName): void | ||
{ | ||
$this->setProperty($target, 'monitorName', $monitorName); | ||
} | ||
|
||
public function getMonitorName(object $target): ?string | ||
{ | ||
return $this->getProperty($target, 'monitorName'); | ||
} | ||
|
||
public function setGraceTimeInMinutes(object $target, int $graceTimeInMinutes): void | ||
{ | ||
$this->setProperty($target, 'graceTimeInMinutes', $graceTimeInMinutes); | ||
} | ||
|
||
public function getGraceTimeInMinutes(object $target): ?int | ||
{ | ||
return $this->getProperty($target, 'graceTimeInMinutes'); | ||
} | ||
|
||
public function setDoNotMonitor(object $target, bool $doNotMonitor = true): void | ||
{ | ||
$this->setProperty($target, 'doNotMonitor', $doNotMonitor); | ||
} | ||
|
||
public function getDoNotMonitor(object $target): ?bool | ||
{ | ||
return $this->getProperty($target, 'doNotMonitor'); | ||
} | ||
|
||
public function setDoNotMonitorAtOhDear(object $target, bool $doNotMonitorAtOhDear = true): void | ||
{ | ||
$this->setProperty($target, 'doNotMonitorAtOhDear', $doNotMonitorAtOhDear); | ||
} | ||
|
||
public function getDoNotMonitorAtOhDear(object $target): ?bool | ||
{ | ||
return $this->getProperty($target, 'doNotMonitorAtOhDear'); | ||
} | ||
|
||
public function setStoreOutputInDb(object $target, bool $storeOutputInDb = true): void | ||
{ | ||
$this->setProperty($target, 'storeOutputInDb', $storeOutputInDb); | ||
} | ||
|
||
public function getStoreOutputInDb(object $target): ?bool | ||
{ | ||
return $this->getProperty($target, 'storeOutputInDb'); | ||
} | ||
|
||
|
||
protected function setProperty(object $target, string $key, mixed $value): void | ||
{ | ||
data_set($this->store, $this->makeKey($target, $key), $value); | ||
} | ||
|
||
protected function getProperty(object $target, string $key): mixed | ||
{ | ||
return data_get($this->store, $this->makeKey($target, $key)); | ||
} | ||
|
||
protected function makeKey(object $target, string $key): array | ||
{ | ||
return [ | ||
$target::class, | ||
spl_object_hash($target), | ||
$key, | ||
]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use Spatie\ScheduleMonitor\Support\Concerns\UsesMonitoredScheduledTasks; | ||
use Spatie\ScheduleMonitor\Support\ScheduledTasks\MonitoredScheduledTasks; | ||
|
||
it('can resolve schedule monitoring configurations repository', function () { | ||
$concern = new class() { | ||
use UsesMonitoredScheduledTasks; | ||
}; | ||
|
||
$repository = $concern->getScheduleMonitoringConfigurationsRepository(); | ||
|
||
expect($repository)->toBeInstanceOf(MonitoredScheduledTasks::class); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to
getMonitoredScheduledTasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, missed this one.
✅ Renamed