forked from admin/VolcanicAgenticCore
Each chat's jobs live in <workspace>/.volcanic/scheduler/jobs.json. On start the scheduler loads every chat's file, moves the retired shared <agentDir>/scheduler/jobs.json into them and renames it .migrated-<ts>. A VolcanicSecretary jobs.json (bare array) in a chat's folder is converted in place for that chat; the original is kept as .secretary-<ts>. Also adds the VolcanicSecretary data migration plan.
40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||
using Telegram.Bot.Types;
|
||
using Volcanic.AgenticCore.Extensions.Scheduler;
|
||
|
||
namespace Volcanic.AgenticCore.Telegram.Scheduling;
|
||
|
||
/// <summary>Everything the Telegram host does for the scheduler, kept out of the shared host files.</summary>
|
||
public static class SchedulerSetup
|
||
{
|
||
public const string DisabledReply = "Scheduling is turned off on this bot (Scheduler:Enabled).";
|
||
|
||
public const string HelpLines = "\n/jobs – this chat's scheduled prompts and watchers\n/cancel <id> – cancel one of them";
|
||
|
||
public static readonly IReadOnlyList<BotCommand> Menu =
|
||
[
|
||
new() { Command = "jobs", Description = "Scheduled prompts and watchers" },
|
||
new() { Command = "cancel", Description = "Cancel a scheduled job: /cancel <id>" },
|
||
];
|
||
|
||
/// <summary>The <c>Scheduler</c> section; an empty <c>LegacyStorePath</c> becomes <c><agentDir>/scheduler/jobs.json</c>.</summary>
|
||
public static SchedulerOptions Options(IConfiguration section, string agentDir)
|
||
{
|
||
var options = section.Get<SchedulerOptions>() ?? new SchedulerOptions();
|
||
if (string.IsNullOrWhiteSpace(options.LegacyStorePath)) options.LegacyStorePath = SchedulerOptions.DefaultLegacyStorePath(agentDir);
|
||
return options;
|
||
}
|
||
|
||
/// <summary>Runner, scheduler, delivery and the hosted service (register after <c>PollingService</c>). Only when enabled.</summary>
|
||
public static void Register(IServiceCollection services)
|
||
{
|
||
services.TryAddSingleton(TimeProvider.System);
|
||
services.AddSingleton<IScriptRunner, ScriptRunner>();
|
||
services.AddSingleton<JobScheduler>();
|
||
services.AddSingleton<TelegramJobDelivery>();
|
||
services.AddHostedService<SchedulerHostedService>();
|
||
}
|
||
}
|