

GitHub - shipsaas/safe-dispatcher: Laravel SafeDispatcher dispatches your Queue...
source link: https://github.com/shipsaas/safe-dispatcher
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Laravel Safe Dispatcher for Queues
For Laravel, it has the Queues feature, all cool and easy to use, right?
But what if it fails to dispatch a job? Then you have no idea for:
- What was the data inside the msg?
- What was the error? Traces?
- How to resend the Queue msg with minimal effort?
Then it will cost you a lot of time to check the log, sentry issues, create retry command,... Awful, IKR?
Worries no more, SafeDispatcher got your back. Check out how it works below.
Documentation:
How SafeDispatcher works?
SafeDispatcher will:
- Store the failed to dispatch msgs.
- Retry them on demand.
- You can even change the connection driver or the name on retry.
- Would really come in handy when you have a
SQSException
(size > 256kb), then you can resend using redis/database driver.
- Would really come in handy when you have a
- Ensure that your processing/flow is still working properly (no 500 server error from HTTP or exceptions from queue worker).
- Super useful & helpful for mission-critical apps.
Requirements
- Laravel 9+ & 10+
- PHP 8.1 & 8.2
Installation
composer require shipsaas/safe-dispatcher
Usage
Dependency Injection
use SaasSafeDispatcher\Bus\SafeDispatcher;
class RegisterService
{
public function __construct(public SafeDispatcher $dispatcher) {}
public function register(): void
{
$user = User::create();
$job = new SendEmailToRegisteredUser($user);
$this->dispatcher->dispatch($job);
}
}
Use Trait for your Job
use SaasSafeDispatcher\Traits\SafeDispatchable;
class SendEmailToRegisteredUser implements ShouldQueue
{
use SafeDispatchable;
}
SendEmailToRegisteredUser::safeDispatch($user);
Quick Helper Functions
safeDispatch(new SendEmailToRegisteredUser($user));
safeDispatch(() => echo('Hello'));
safeDispatchSync(new SendEmailToRegisteredUser($user));
Cover Queue Facade (v1.2.0+)
use SaasSafeDispatcher\Services\SafeQueue;
SafeQueue::prepareFor(new Job())
->push('high'); # Push to "high" queue name
Learn more Cover Queue Facade
Notes
- SafeDispatcher hasn't supported with batching & chaining.
- Alternatively, you can do normal
::safeDispatch
and after finish your job, dispatch another,...
- Alternatively, you can do normal
- SafeDispatcher considers the
sync
Queue as a Queue Msg.- Therefore, if the handling fails, Queue Msg will be stored too.
- SafeDispatcher ships some helpful APIs too, check it out: APIs
Tests
SafeDispatcher is not only have normal Unit Testing but also Integration Test (interacting with MySQL for DB and Redis for Queue).
We're planning to add other queue drivers too (database or SQS).
To run the test, hit this:
composer test
Contribute to the project
- All changes must follow PSR-1 / PSR-12 coding conventions.
- Unit testing is a must, cover things as much as you can.
Maintainers & Contributors
- Seth Phat
Join me
This library is useful?
Thank you, please give it a to support the project.
Don't forget to share with your friends & colleagues
License
Copyright © by ShipSaaS 2023 - Under MIT License.
Recommend
-
207
dispatch.vim Leverage the power of Vim's compiler plugins without being bound by synchronicity. Kick off builds and test suites using one of several asynchronous adapters (including tmux, screen, iTerm, Windows, and a headless mode), and...
-
43
Simple and light-weight event dispatcher for Kotlin
-
35
Author’s note: In this post while explaining where a certain programming language comes from, I use the terms “JavaScript” and “ECMAScript™” interchangeably. There is a difference, but it’s pedantic and not worth getting...
-
12
Reconstruct Instead of Validating • ButtondownButtondown is the easiest way to build and run your newsletter. 2020...
-
18
If you're running your queue workers on a server with limited resources, or a server that's also used to serve HTTP requests and do other tasks, it's important to ration the resource used by those workers.Workers Memory Consumption
-
8
June 29, 2021 ...
-
6
News » Insights » Ignition Lane’s Weekly Wrap: Hatches, matches & startup dispatches; all the raises;...
-
9
Quantum Library : A scalable C++ coroutine framework Quantum is a full-featured and powerful C++ framework build on top of the Boost...
-
8
Multi-Cluster Application Dispatcher The multi-cluster-app-dispatcher is a Kubernetes controller providing mechanisms for applications to manage batch jobs in a single or mult-cluster environment. The multi-clust...
-
2
Dispatches from the Northwestern University Liberated ZoneDay 1 of calling for divestment.12 min read5 days ago
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK