forked from admin/VolcanicAgenticCore
- JobScheduler: a stored job whose zone lookup throws no longer fails StartAsync; timer re-armed under the lock; a delivery cut off by shutdown isn't recorded (one-offs fire again after restart); CancelJobAsync in one step - Schedules.ParseAt: ISO 8601 with a date only (no machine-clock date for a bare 09:00) - core: a FollowUp prompt that loses the race to a starting run joins it as a follow-up, not steering - Telegram: TimeZoneFor tolerates non-numeric targets; RunPromptAsync waits only when queued; one agent dir - ScriptRunner: bad workspace paths are Failed, not exceptions; zone id helpers share TimeZoneIds.ToIana's rule - tests: no wall-clock sleeps in scheduler tests; transcript-entry, disabled-scheduler and failing-prompt coverage - docs: spec notes for the above; README row for the scheduler
54 lines
2.7 KiB
C#
54 lines
2.7 KiB
C#
using System.Globalization;
|
|
using System.Text;
|
|
|
|
namespace Volcanic.AgenticCore.Extensions.Scheduler;
|
|
|
|
/// <summary>How jobs and times are shown (the <c>schedule</c> tool, <c>/jobs</c>, zone-change replies). Invariant culture, 24 h.</summary>
|
|
public static class JobFormat
|
|
{
|
|
public static string Icon(JobKind kind) => kind switch { JobKind.Reminder => "⏰", JobKind.Prompt => "💬", _ => "🔍" };
|
|
|
|
/// <summary><c>27 Sep 09:00</c> in <paramref name="zone"/>.</summary>
|
|
public static string DayTime(DateTimeOffset at, TimeZoneInfo zone) =>
|
|
TimeZoneInfo.ConvertTime(at, zone).ToString("d MMM HH:mm", CultureInfo.InvariantCulture);
|
|
|
|
/// <summary><c>14:10</c> when on the same local day as <paramref name="now"/>, else <see cref="DayTime"/>.</summary>
|
|
public static string When(DateTimeOffset at, TimeZoneInfo zone, DateTimeOffset now)
|
|
{
|
|
var local = TimeZoneInfo.ConvertTime(at, zone);
|
|
return local.Date == TimeZoneInfo.ConvertTime(now, zone).Date
|
|
? local.ToString("HH:mm", CultureInfo.InvariantCulture)
|
|
: DayTime(at, zone);
|
|
}
|
|
|
|
/// <summary><c>Sat 2026-09-26 14:03</c> (the model-facing form: weekday and full date).</summary>
|
|
public static string Stamp(DateTimeOffset at, TimeZoneInfo zone) =>
|
|
TimeZoneInfo.ConvertTime(at, zone).ToString("ddd yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
|
|
|
|
public static string ZoneName(TimeZoneInfo zone) => ZoneNames.Name(zone);
|
|
|
|
/// <summary><c>exit 1</c>, <c>exit 1, timed out</c>, <c>timed out</c>, or <c>did not start</c>.</summary>
|
|
public static string FailureReason(JobResult result) => result switch
|
|
{
|
|
{ ExitCode: { } code, TimedOut: true } => $"exit {code.ToString(CultureInfo.InvariantCulture)}, timed out",
|
|
{ ExitCode: { } code } => $"exit {code.ToString(CultureInfo.InvariantCulture)}",
|
|
{ TimedOut: true } => "timed out",
|
|
_ => "did not start",
|
|
};
|
|
|
|
/// <summary><c>`k7m2q` ⏰ Call the dentist · once 27 Sep 09:00</c>; cron jobs show the expression and the next run; a failed last run is appended.</summary>
|
|
public static string Line(JobView view, TimeZoneInfo zone, DateTimeOffset now)
|
|
{
|
|
var job = view.Job;
|
|
var sb = new StringBuilder().Append('`').Append(job.Id).Append("` ").Append(Icon(job.Kind)).Append(' ').Append(job.Name);
|
|
if (job.Schedule.At is { } at) sb.Append(" · once ").Append(DayTime(at, zone));
|
|
else
|
|
{
|
|
sb.Append(" · `").Append(job.Schedule.Cron).Append('`');
|
|
if (view.NextRunAt is { } next) sb.Append(" · next ").Append(When(next, zone, now));
|
|
}
|
|
if (job.LastResult is { Ok: false } failed) sb.Append(" · last: failed (").Append(FailureReason(failed)).Append(')');
|
|
return sb.ToString();
|
|
}
|
|
}
|