Download the PHP package tetthys/claim-dispatch without Composer
On this page you can find all versions of the php package tetthys/claim-dispatch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package claim-dispatch
tetthys/claim-dispatch
Atomic claim-dispatch framework for Laravel
Safely schedule and dispatch jobs from a single action log table.
✨ Features
- Single table (
action_logs) as a durable schedule - Atomic claim – prevent duplicate dispatch across workers
- Processors – type-based mapping from log row → Job
- Idempotent jobs – designed for safe re-execution
- Universal publisher – domain-agnostic, higher-order & fluent
- Publisher Facade – simple static API:
Publisher::quick(...) - Configurable – add your own processors, rules, and evaluation logic
📦 Installation
`
Publish config and migration:
⚡ Quick Start
1. Define a Processor
Suppose you want to schedule welcome emails.
Each log row with type = email.welcome should become a SendWelcomeEmail Job.
Register it in config/claim-dispatch.php:
2. Publish an Action Log
👉 Using the Facade (recommended)
Facade
Publisheris available if you addto your
config/app.phpaliases (or rely on auto-discovery).
3. Run the Scheduler
Add to app/Console/Kernel.php:
Start a queue worker:
🧩 How It Works
-
Publish Insert a row into
action_logs:type= routing key (e.g.email.welcome)payload= JSON data (email address, etc.)end_at= earliest eligible time
-
Scheduler Runs every minute (or via cron). Atomically claims rows (
end_at <= now() AND claimed_at IS NULL) and dispatches them to processors. -
Processor → Job Each processor transforms the record into a Laravel Job. Jobs must be idempotent.
- Execution
Queue workers run the jobs.
After success, the row is marked
processed_at.
✅ Example Workflow
- A new user signs up.
- The app publishes an
email.welcomelog with their email and a 5-minute delay. - After 5 minutes, the scheduler claims it and dispatches
SendWelcomeEmail. - The Job sends the email.
- Even with multiple workers, it is dispatched exactly once.
🔧 Advanced
-
Rules & Gates
rules([...]): store declarative predicates in payload (__rules).when(fn ($payload) => ...): only insert if predicate passes.skipIf(fn ($payload) => ...): skip insert if predicate passes.- Processors can evaluate
__rulesas a second guard.
-
Idempotency Provide a stable key with
idempotency($key). Prevents duplicate rows for the same logical event. - Multiple domains
Just add more processors (
email.newsletter,report.generate, …).
📖 License
MIT