Skip to content
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 9 commits into from
Jan 6, 2025

Conversation

m-bymike
Copy link
Contributor

@m-bymike m-bymike commented Aug 5, 2024

Instead of declaring runtime properties in the macros, we delegate storage of configuration properties to an extra class.

This aims at issue #103.

I open this pull request with a potential solution to #103, and I'm very open to discuss my approach. It should serve as a conversation starter, I don't consider it done by now :).

Instead of declaring runtime properties in the macros, we delegate storage of configuration properties to an extra class.
@m-bymike
Copy link
Contributor Author

m-bymike commented Sep 9, 2024

:)

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good. Did you already test these changes in a real Laravel app?


class ScheduleMonitoringConfigurationsRepository
{
private array $store = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a docblock that shows the content of this array.

Alternatively you could introduce a MonitoredScheduledTask class and put that in the array

}


private function setProperty(object $target, string $key, mixed $value): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use private in our OSS code. Could you make everything that is now private protected?

$this->monitorName = $monitorName;
$this->app->singleton(
Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository::class,
static fn () => new Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import this namespace

$this->monitorName = $monitorName;
$this->app->singleton(
Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository::class,
static fn () => new Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the static keyword

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it's a habit, if consistently used, it can bring some performance optimisations. It's a micro optimisation nevertheless, so I removed it.

);

/** @var Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository $scheduleMonitoringConfigurationsRepository */
$scheduleMonitoringConfigurationsRepository = $this->app->make(Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to the more human monitoredScheduledTasks


use Spatie\ScheduleMonitor\Support\ScheduledTasks\ScheduleMonitoringConfigurationsRepository;

trait UsesScheduleMonitoringConfigurationsRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to usesMonitoredScheduledTasks


namespace Spatie\ScheduleMonitor\Support\ScheduledTasks;

class ScheduleMonitoringConfigurationsRepository
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to monitoredScheduledTasks

m-bymike and others added 2 commits December 25, 2024 13:52
Replaced `ScheduleMonitoringConfigurationsRepository` with `MonitoredScheduledTasks` for better clarity and organization. Deprecated old traits and added corresponding replacements, updating references and tests accordingly to maintain functionality.
@m-bymike
Copy link
Contributor Author

Hi @freekmurze ,

thank you for the review, I addressed all suggested changes.

So far I tested the changes only locally (including the latest version) in a large project where it works as expected.


trait UsesMonitoredScheduledTasks
{
public function getScheduleMonitoringConfigurationsRepository(): MonitoredScheduledTasks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to getMonitoredScheduledTasks

Copy link
Contributor Author

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

@freekmurze
Copy link
Member

Seems that the tests are failing, could you take a look at that too?

@m-bymike
Copy link
Contributor Author

Seems that the tests are failing, could you take a look at that too?

Just did, one of them uncovered a line that I missed, which has now been fixed (534e4e0). The other failing test was because of a difference in the name of the testing environment. I chose to use a dynamic way to retrieve the name of the current environment (00045a4).

Then I figured that the tests only include PHP 8.0 - 8.2, so I added 8.3 and 8.4. At the same time I removed 8.0 as it is EoL (3811a44).

And I also updated the PHP version requirement in the composer.json file to ^8.1 (f0298c0).

@freekmurze freekmurze merged commit cbdab21 into spatie:main Jan 6, 2025
22 checks passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants