Installation Add Talon to your Laravel project via Composer:
composer require phalcon/talon
Publish the config file (if available) and run migrations (if applicable).
Core Concepts
Talon\Workflow – Defines a workflow with steps.Talon\Step – Individual tasks in a workflow (e.g., database operations, API calls, file processing).Talon\Runner – Executes workflows with retries, timeouts, and logging.First Use Case: Simple Workflow Define a workflow in a service class or directly in a controller:
use Phalcon\Talon\Workflow;
use Phalcon\Talon\Step;
$workflow = new Workflow('user_export');
$workflow->step(new Step('fetch_users', function () {
return User::all();
}))
->step(new Step('export_to_csv', function ($users) {
// Export logic here
}));
$result = $workflow->run();
// app/Workflows/ProcessOrder.php
class ProcessOrder extends Workflow
{
public function __construct()
{
$this->step(new Step('validate_order', [OrderValidator::class, 'validate']))
->step(new Step('update_inventory', [InventoryService::class, 'deductStock']))
->step(new Step('send_notification', [NotificationService::class, 'dispatch']));
}
}
$workflow->step(new Step('custom_step', fn($data) => $this->customLogic($data)));
$workflow->step(new Step('api_call', [ApiService::class, 'fetchData'])
->retry(3)
->fallback(fn() => $this->handleFallback())
);
'workflows' => [
'default_retry_attempts' => 2,
'timeout_seconds' => 30,
],
ProcessOrder::dispatch()->onQueue('workflows');
event(new OrderPlaced($order));
// Inside listener:
ProcessOrder::dispatch($order);
Artisan::call('workflow:run', ['name' => 'user_export']);
$workflow->setLogger(app(\Monolog\Logger::class));
$workflow->trackInDatabase(); // Hypothetical method
State Management
// Bad: Assumes $users exists globally
$workflow->step(new Step('export', [Exporter::class, 'export']));
// Good: Explicitly pass data
$workflow->step(new Step('export', [Exporter::class, 'export'], ['users' => $users]));
Circular Dependencies
WorkflowA calls WorkflowB, which calls WorkflowA).Performance Bottlenecks
$workflow->step(new Step('slow_task')->parallel());
Configuration Overrides
config/talon.php) may override step-specific settings.$workflow->step(new Step('debug_step')->logOutput());
dd($workflow->getSteps()); // View all steps before execution
$step = new Step('test_step', [TestService::class, 'run']);
$result = $step->execute(['input' => 'data']); // Test without full workflow
Custom Step Types
Extend Talon\Step to add domain-specific logic:
class DatabaseStep extends Step
{
public function execute($data)
{
return DB::table('users')->where('active', 1)->get();
}
}
Middleware for Steps Add pre/post-processing:
$workflow->step(new Step('log_step')
->middleware([LogMiddleware::class, 'before'])
->middleware([LogMiddleware::class, 'after'])
);
Event Hooks Listen for workflow events (if supported):
event(new WorkflowStarting($workflow));
$workflow->step(new Step('task1')->parallel())
->step(new Step('task2')->parallel());
How can I help you explore Laravel packages today?