Automation administration dashboard
* Manual automations * Scheduled automations * Incoming webhook triggers * Domain-event trigger foundation * Ordered automation steps * Queued execution * Run status and execution history * Per-step execution logs * Continue-or-stop-on-failure control * Email actions * Outgoing webhook actions * Application log actions * Delay actions * Secure incoming webhook secrets * Automation trigger and action registries * Extensible action and trigger contracts * Scheduled automation Artisan command * Administration navigation * Automation permissions * Module registration and boot test
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace Modules\Automation\Jobs;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Modules\Automation\Contracts\ActionRegistry;
|
||||
use Modules\Automation\Models\AutomationRun;
|
||||
final class ExecuteAutomation implements ShouldQueue
|
||||
{
|
||||
use Dispatchable,InteractsWithQueue,Queueable,SerializesModels;
|
||||
public function __construct(public readonly int $runId) {}
|
||||
public function handle(ActionRegistry $actions): void
|
||||
{
|
||||
$run=AutomationRun::with('automation.steps')->findOrFail($this->runId); $automation=$run->automation;
|
||||
$run->update(['status'=>'running','started_at'=>now()]);
|
||||
try {
|
||||
foreach($automation->steps->where('is_enabled',true) as $step) {
|
||||
$run->update(['current_step'=>$step->position]);
|
||||
try { $result=$actions->execute($step,$run->payload??[]); $run->logs()->create(['automation_step_id'=>$step->id,'level'=>'info','message'=>$step->name?:$step->action_type.' completed','context'=>$result,'created_at'=>now()]); }
|
||||
catch(\Throwable $e) { $run->logs()->create(['automation_step_id'=>$step->id,'level'=>'error','message'=>$e->getMessage(),'created_at'=>now()]); if($automation->stop_on_failure) throw $e; }
|
||||
}
|
||||
$run->update(['status'=>'completed','finished_at'=>now()]);
|
||||
} catch(\Throwable $e) { $run->update(['status'=>'failed','error'=>$e->getMessage(),'finished_at'=>now()]); throw $e; }
|
||||
finally { $automation->increment('run_count'); $automation->update(['last_ran_at'=>now()]); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user