37116f0329
A schedule (script, arguments, targets, exclusions, stagger) now owns 1..20 triggers in ScheduleTriggers: Recurring, Once, On Enrollment, On Agent Ready, At Logon and On Demand, each with its own next/last run and, for events, a repeat (every time, once per device, once per user per device). The sweep fires a schedule once however many of its triggers are due. At Logon fires on the agent's logon events with the user and session; a Delay After Logon becomes a start time on the device's clock (logon time plus delay) that the agent waits out. On Demand makes the script available to the schedule's targets minus exclusions; a device asks over NATS to start it by schedule or script id or name (ambiguity refused with the candidates), its text parameters checked like the console's, and the run is a normal job with source 'device', audited with the device as actor. Migration ScheduleTriggerList (SQLite, Postgres, SQL Server) moves each schedule's timing into one trigger under the schedule's own id, so once-per-device records keep matching; Down throws (lossy). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using Backend.Data;
|
|
using Backend.Groups;
|
|
using Shared.Contracts.Models;
|
|
|
|
namespace Backend.Tests;
|
|
|
|
/// <summary>Seeding helpers for a schedule's triggers.</summary>
|
|
internal static class ScheduleTestKit
|
|
{
|
|
/// <summary>Adds a trigger to the schedule (in list order) and returns the schedule.</summary>
|
|
public static ScriptTriggerEntity With(
|
|
this ScriptTriggerEntity schedule, ScriptTriggerType type, string? cron = null, DateTimeOffset? runOnce = null,
|
|
DateTimeOffset? nextRun = null, TriggerRepeat? repeat = null, int delaySeconds = 0, Guid? id = null)
|
|
{
|
|
schedule.Triggers.Add(new ScheduleTriggerEntity
|
|
{
|
|
Id = id ?? Guid.NewGuid(),
|
|
ScheduleId = schedule.Id,
|
|
Position = schedule.Triggers.Count,
|
|
Type = type,
|
|
CronExpression = cron,
|
|
RunOnceUtc = runOnce,
|
|
NextRunUtc = nextRun,
|
|
Repeat = repeat ?? ScheduleTriggers.DefaultRepeat(type),
|
|
DelaySeconds = delaySeconds,
|
|
});
|
|
return schedule;
|
|
}
|
|
|
|
/// <summary>The schedule's first trigger (its timing, for a single-trigger schedule).</summary>
|
|
public static ScheduleTriggerEntity Timing(this ScriptTriggerEntity schedule)
|
|
=> schedule.Triggers.OrderBy(t => t.Position).First();
|
|
}
|