/// <summary> /// This method register the job expiry task. /// </summary> protected override void JobSchedulesManualRegister() { var job = new CommandJobSchedule(ScheduleExpireEntities , Policy.JobPollSchedule , name: $"EntityCacheHandlerBase: {typeof(E).Name} Expire Entities" , isLongRunning: Policy.JobPollIsLongRunning); Scheduler.Register(job); }
/// <summary> /// Creates and registers a schedule. /// </summary> /// <param name="execute">The execution function.</param> /// <param name="timerConfig">The timer poll configuration. If this is set to null, the schedule will fire immediately after it is registered.</param> /// <param name="context">The optional schedule context</param> /// <param name="name">The name of the schedule.</param> /// <param name="isLongRunning">A boolean flag that specifies whether the process is long running.</param> /// <param name="tearUp">The set up action.</param> /// <param name="tearDown">The clear down action.</param> /// <returns>Returns the new master job schedule.</returns> protected virtual CommandJobSchedule MasterJobScheduleRegister(Func <Schedule, CancellationToken, Task> execute , ScheduleTimerConfig timerConfig = null , object context = null , string name = null , bool isLongRunning = false , Action <Schedule> tearUp = null , Action <Schedule> tearDown = null) { var schedule = new CommandJobSchedule(); schedule.Initialise(execute, timerConfig, context, name, isLongRunning, tearUp, tearDown, true); return(JobScheduleRegister(schedule)); }
/// <summary> /// Creates and registers a schedule. /// </summary> /// <param name="execute">The execution function.</param> /// <param name="interval">The poll interval.</param> /// <param name="initialWait">The initial wait.</param> /// <param name="initialWaitUTCTime">The optional initial UTC wait time that the polling will begin if the initialWait is set to null.</param> /// <param name="context">The optional schedule context</param> /// <param name="name">The name of the schedule.</param> /// <param name="isLongRunning">A boolean flag that specifies whether the process is long running.</param> /// <param name="tearUp">The set up action.</param> /// <param name="tearDown">The clear down action.</param> /// <param name="isMasterJob">Indicates whether this schedule is associated to a master job.</param> /// <returns>Returns the new schedule.</returns> protected virtual CommandJobSchedule JobScheduleRegister(Func <Schedule, CancellationToken, Task> execute , TimeSpan?interval = null , TimeSpan?initialWait = null , DateTime?initialWaitUTCTime = null , object context = null , string name = null , bool isLongRunning = false , Action <Schedule> tearUp = null , Action <Schedule> tearDown = null , bool isMasterJob = false) { var schedule = new CommandJobSchedule(); schedule.Initialise(execute, new ScheduleTimerConfig(interval, initialWait, initialWaitUTCTime, false), context, name, isLongRunning, tearUp, tearDown, isMasterJob); return(JobScheduleRegister(schedule)); }
/// <summary> /// Jobs the schedule unregister. /// </summary> /// <param name="schedule">The schedule.</param> /// <returns></returns> protected virtual bool JobScheduleUnregister(CommandJobSchedule schedule) { try { schedule.TearDown?.Invoke(schedule); } catch (Exception ex) { StatisticsInternal.Ex = ex; Collector?.LogException($"Job '{schedule.Name} could not be teared down.'", ex); } var success = Scheduler.Unregister(schedule); if (success) { FireAndDecorateEventArgs(OnScheduleChange, () => new ScheduleChangeEventArgs(true, schedule)); } return(success); }
/// <summary> /// Jobs the schedule register. /// </summary> /// <param name="schedule">The schedule.</param> /// <returns>Returns the schedule.</returns> protected virtual CommandJobSchedule JobScheduleRegister(CommandJobSchedule schedule) { try { schedule.TearUp?.Invoke(schedule); } catch (Exception ex) { StatisticsInternal.Ex = ex; Collector?.LogException($"Job '{schedule.Name} could not be teared up.'", ex); } //Set the identifiers for debug. schedule.CommandId = ComponentId; schedule.CommandName = FriendlyName; Scheduler.Register(schedule); mSchedules.Add(schedule); FireAndDecorateEventArgs(OnScheduleChange, () => new ScheduleChangeEventArgs(false, schedule)); return(schedule); }
/// <summary> /// Initializes a new instance of the <see cref="ScheduleChangeEventArgs"/> class. /// </summary> /// <param name="isRemoval">True if the schedule is being removed.</param> /// <param name="schedule">The schedule.</param> public ScheduleChangeEventArgs(bool isRemoval, CommandJobSchedule schedule) { IsRemoval = isRemoval; Schedule = schedule; }