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

Add queue jobs check #143

Merged
merged 4 commits into from
Dec 28, 2022
Merged

Add queue jobs check #143

merged 4 commits into from
Dec 28, 2022

Conversation

stfndamjanovic
Copy link
Contributor

This PR is adding the possibility to monitor queue jobs. It is working almost the same as the scheduled check. The only difference is that this check will just dispatch a job, and detects if the queue job is run within five minutes. If not, the check will fail.

This is how it can be registered.

use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\QueueCheck;

Health::checks([
    QueueCheck::new(),
]);

And you can change the heartbeat check as you can do with the schedule check.

QueueCheck::new()->heartbeatMaxAgeInMinutes(10),

Also, one additional cron job needs to be registered in order to dispatch the heartbeat queue job.

// in app/Console/Kernel.php
use \Spatie\Health\Commands\QueueCheckHeartbeatCommand;

public function schedule(Schedule $schedule) {
    // your other commands

    $schedule->command(QueueCheckHeartbeatCommand::class)->everyMinute();
}

Not sure if 5 minutes would work for everyone, but let's discuss it only if this PR is acceptable to you. 🙂

@freekmurze
Copy link
Member

I like the functionality 👍 Could you also add an example on how to track different queues?

The introduction of an HeartbeatCheck interface seems a bit overkill to me. Let's remove that and keep the different checks that rely on a heartbeat be independent of each other.

@stfndamjanovic
Copy link
Contributor Author

Hey @freekmurze, glad to hear that you like the functionality!

I have just two questions. By tracking different queues, do you mean something like this?

Health::checks([
    QueueCheck::new()->onQueue('email'),
]);

Or do you want the possibility to track many different queues? Something like this.

Health::checks([
    QueueCheck::new()->onQueues(['email', 'payment']),
]);

And the second question is, do you want to remove just the HeartbeatCheck interface and keep the HasHeartbeatCheck trait and abstract class HeartbeatCommand, or do you want to remove them as well?

@freekmurze
Copy link
Member

Ideally, both of your code examples would work 🙂

I would remove both the abstract class and the trait. I like to keep all the check independent from each other.

@stfndamjanovic
Copy link
Contributor Author

Thanks for the clarification Freek.

Both abstract class and trait have been removed. Examples of tracking different queues are part of the docs file.

How it's working now? If you specify more than one queue that you want to track and if any of them fail, the result will be failed and in meta will be explained which queue failed and why. If all queues are fine, the result will be a success.

Let me know if anything else should be changed, or improved.

@freekmurze freekmurze merged commit cf70f34 into spatie:main Dec 28, 2022
@freekmurze
Copy link
Member

Thank you, I'll polish this a bit an release it 👍

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