spatie / laravel-slack-alerts

Quickly send a message to Slack
https://freek.dev/2172-a-package-to-quickly-send-slack-alerts-in-a-laravel-app
MIT License
281 stars 33 forks source link

Add queue support for Slack alerts #47

Closed mcpuishor closed 4 months ago

mcpuishor commented 4 months ago

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:")
Nielsvanpach commented 4 months ago

Could you have a look at the failing tests?

Nielsvanpach commented 4 months ago

The tests are still failing

freekmurze commented 4 months ago

Thanks!