trypost/app/Console/Commands/Automation/ProcessAutomationDelays.php
Paulo Castellano 9a692b4608 Enhance automation functionality: Introduce workflow variables and improve node validation
- Added support for workflow variables in automations, allowing users to define reusable values.
- Implemented validation for Generate nodes to ensure intended image counts align with selected accounts.
- Updated automation models and requests to handle new variables, including encryption for sensitive data.
- Enhanced UI to display variables and their management within the automation editor.
- Improved error handling for webhook and HTTP nodes to prevent requests to invalid URLs.
- Refactored various components for better context resolution during automation runs.
2026-06-11 15:47:29 -03:00

48 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Console\Commands\Automation;
use App\Actions\Automation\Run\AdvanceAutomationRun;
use App\Enums\Automation\Run\Status;
use App\Enums\Automation\Status as AutomationStatus;
use App\Models\AutomationRun;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
#[Signature('automation:process-delays')]
#[Description('Wake up runs that finished their delay window')]
class ProcessAutomationDelays extends Command
{
public function handle(AdvanceAutomationRun $advance): int
{
AutomationRun::query()
->where('status', Status::Waiting)
->where('next_action_at', '<=', now())
->where(fn ($query) => $query
->where('is_manual', true)
->orWhereHas('automation', fn ($inner) => $inner->where('status', AutomationStatus::Active)))
->chunkById(50, function ($runs) use ($advance) {
foreach ($runs as $run) {
$claimed = AutomationRun::query()
->whereKey($run->id)
->where('status', Status::Waiting)
->update([
'status' => Status::Running,
'next_action_at' => null,
]);
if ($claimed === 0) {
continue;
}
$run->refresh();
$advance($run, $run->current_node_id);
}
});
return self::SUCCESS;
}
}