forked from admin/VolcanicAgenticCore
Jobs are prompts or watchers. A reminder is a prompt the agent passes on, so
it lands in the transcript. Stored reminder jobs load as prompts
("Remind me: <text>"). Also records the Coolify deploy target in CLAUDE.md.
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 == 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();
|
|
}
|
|
}
|