Replace magic strings across the automation domain with backed PHP enums
(HttpMethod, AuthType, DelayUnit, ScheduleField) and mirrored TS consts
(http-method, auth-type, delay-unit, schedule-field, condition-operator,
publish-mode), plus the existing Condition\Handle / Operator / Publish\Mode.
Also:
- require scheduled_offset via concrete-index required_if instead of
defaulting to 60 when the publish mode is scheduled
- fail the webhook node explicitly when the resolved url is empty
- localize node failure messages (fetch_rss/http/webhook)
- cast resolver/strtoupper inputs to string so a present-null config value
degrades gracefully instead of crashing
- list automations with config('app.pagination.default'), drop the perPage param
28 lines
860 B
PHP
28 lines
860 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Automation\Node;
|
|
|
|
use App\DataTransferObjects\Automation\NodeRunResult;
|
|
use App\Enums\Automation\DelayUnit;
|
|
use App\Models\AutomationRun;
|
|
use InvalidArgumentException;
|
|
|
|
class RunDelayNode
|
|
{
|
|
public function __invoke(AutomationRun $run, array $config): NodeRunResult
|
|
{
|
|
$duration = (int) data_get($config, 'duration', 0);
|
|
$unit = data_get($config, 'unit', DelayUnit::Minutes->value);
|
|
|
|
$until = match (DelayUnit::tryFrom((string) $unit)) {
|
|
DelayUnit::Minutes => now()->addMinutes($duration),
|
|
DelayUnit::Hours => now()->addHours($duration),
|
|
DelayUnit::Days => now()->addDays($duration),
|
|
default => throw new InvalidArgumentException("Unknown delay unit: {$unit}"),
|
|
};
|
|
|
|
return NodeRunResult::sleep($until);
|
|
}
|
|
}
|