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\Services;
|
||||
use Illuminate\Support\Str;
|
||||
use Modules\Automation\Jobs\ExecuteAutomation;
|
||||
use Modules\Automation\Models\Automation;
|
||||
use Modules\Automation\Models\AutomationRun;
|
||||
final class AutomationRunner
|
||||
{
|
||||
public function dispatch(Automation $automation,array $payload=[],?string $triggerType=null): AutomationRun
|
||||
{
|
||||
abort_unless($automation->isActive(),422,'Automation is not active.');
|
||||
$run=$automation->runs()->create(['execution_id'=>(string)Str::uuid(),'trigger_type'=>$triggerType??$automation->trigger_type,'payload'=>$payload,'status'=>'queued']);
|
||||
ExecuteAutomation::dispatch($run->id)->onQueue(config('automation.queue','default'));
|
||||
return $run;
|
||||
}
|
||||
public function dispatchMatching(string $triggerType,array $payload=[],array $constraints=[]): int
|
||||
{
|
||||
$query=Automation::query()->where('status','active')->where('trigger_type',$triggerType);
|
||||
$count=0; foreach($query->get() as $automation) { if($this->matches($automation,$constraints)){ $this->dispatch($automation,$payload,$triggerType); $count++; } }
|
||||
return $count;
|
||||
}
|
||||
private function matches(Automation $automation,array $constraints): bool
|
||||
{
|
||||
$config=$automation->trigger_config??[];
|
||||
foreach($constraints as $key=>$value) if(isset($config[$key]) && (string)$config[$key] !== (string)$value) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user