Skip to content

Commit a07e4f0

Browse files
committed
added tip #342
1 parent 5c9a9c7 commit a07e4f0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Currently, there are over 300 tips categorized as follows:
1919
- 🌐 [API & HTTP Client Tips](./tips/api-and-http-client.md) (14 tips)
2020
- 💡 [Random Cool Tips](./tips/others.md) (16 tips)
2121
- 🖼️ [View Tips](./tips/views.md) (11 tips)
22-
- 📬 [Queues & Job Tips](./tips/queues-and-jobs.md) (13 tips)
22+
- 📬 [Queues & Job Tips](./tips/queues-and-jobs.md) (14 tips)
2323
- 🔒 [Authentication & Authorization Tips](./tips/auth.md) (6 tips)
2424
- 📦 [Laravel Container Tips](./tips/container.md) (7 tips)
2525
- ⚠️ [Error Handling Tips](./tips/error-handling.md) (5 tips)

tips/queues-and-jobs.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [Fail Jobs on Specific Exceptions](#laravel-tip--fail-jobs-on-specific-exceptions-️)
1414
- [Display Remaining Attempts for a Rate-Limited Job](#laravel-tip--display-remaining-attempts-for-a-rate-limited-job-️)
1515
- [Encrypt Your Jobs](#laravel-tip--encrypt-your-jobs-️)
16+
- [Global Middleware for Jobs](#laravel-tip--global-middleware-for-jobs-️)
1617

1718
## Laravel Tip 💡: Dispatch After Response ([⬆️](#queues--jobs-tips-cd-))
1819

@@ -341,3 +342,27 @@ class ProcessPlaidTransaction implements ShouldQueue, ShouldBeEncrypted
341342
}
342343
}
343344
```
345+
346+
## Laravel Tip 💡: Global Middleware for Jobs ([⬆️](#queues--jobs-tips-cd-))
347+
348+
Did you know you can apply global job middleware? It can be really useful for custom logging and monitoring, like instantly notifying Slack or Discord about slower-than-usual jobs 🚀
349+
350+
```php
351+
<?php
352+
353+
namespace App\Providers;
354+
355+
use Illuminate\Support\ServiceProvider;
356+
use Illuminate\Support\Facades\Bus;
357+
use App\Jobs\Middleware\MonitorJobPerformance;
358+
359+
class AppServiceProvider extends ServiceProvider
360+
{
361+
public function boot(): void
362+
{
363+
// Custom middleware that notifies Slack, Discord, etc. about slow jobs
364+
// It will be executed as the last middleware in the stack
365+
Bus::pipeThrough([MonitorJobPerformance::class]);
366+
}
367+
}
368+
```

0 commit comments

Comments
 (0)