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 support for Slack alerts #47

Merged
merged 6 commits into from
May 6, 2024
Merged

Conversation

mcpuishor
Copy link
Contributor

First of all, hello to all. This is my first contribution to an open source package, so please go easy on me. I'm not a software engineer, never developed professionally, but I dabble a bit in the Laravel ecosystem every now and then.

This being said, my use case is as follows: I have two apps, both using the same database as quite a lot of the data is shared between them and there was no reason to duplicate. The jobs queues are running on database connection. Both apps dispatch and process their own jobs on queues with different names. There is also a default queue which is used for processing emails and a few other bits.

Long story short: today I ran into the situation where jobs were failing at an alarming rate on one of the apps, with the following error (excerpt):

Exception: Job is incomplete class: 
{"__PHP_Incomplete_Class_Name":"Spatie\\SlackAlerts\\Jobs\\SendToSlackChannelJob","webhookUrl":"https:\/\/hooks.slack.com.... 

This seems to happen because the wrong app was processing a job that was found on the default queue.

So I needed to have a way to somehow tell Slack Alerts that the job needs to be dispatched on a different queue than default .

The PR introduces a config option slack-alerts.queue, which gets its value from SLACK_ALERT_QUEUE in .env .

At runtime, the queue can be changed by calling onQueue() method.

Example:

 \Spatie\SlackAlerts\Facades\SlackAlert::onQueue('test')->message(":smile: :custom-code:")

Added a new static method getQueue in Config class to get Slack alert queue from configuration. This queue is used in SlackAlert class, where jobs to display message or blocks are now dispatched to it. Additionally, a queue configuration option has been added in slack-alerts configuration file.
The update provides a detailed guide on how to handle message queues.
@Nielsvanpach
Copy link
Member

Could you have a look at the failing tests?

Changed assertions when dispatching on a different queue than default to test the queue rather than the bus.
@mcpuishor mcpuishor marked this pull request as draft April 30, 2024 09:18
@mcpuishor mcpuishor marked this pull request as ready for review April 30, 2024 09:36
@Nielsvanpach
Copy link
Member

The tests are still failing

@freekmurze freekmurze merged commit 7d89a8c into spatie:main May 6, 2024
14 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.

None yet

3 participants