3using System.Threading.Tasks;
19 private static Scheduler scheduler =
null;
20 private bool disposeScheduler =
false;
39 if (scheduler is
null)
42 this.disposeScheduler =
false;
46 this.disposeScheduler =
true;
62 if (this.disposeScheduler)
67 return Task.CompletedTask;
87 if (OnlyIfDifferent &&
92 Schedule.ScheduledExecutionTime.HasValue)
97 if (
Schedule.ScheduledExecutionTime.HasValue)
100 Schedule.ScheduledExecutionTime =
null;
119 BurstCountLeft = Job.BurstCount
127 private static readonly Dictionary<string, JobSchedule> scheduledJobs =
new Dictionary<string, JobSchedule>();
129 private class JobSchedule
132 public DateTime? ScheduledExecutionTime =
null;
133 public DateTime? ExecutionTime =
null;
135 public Duration? BurstInterval =
null;
136 public int BurstCount = 1;
137 public int BurstCountLeft = 1;
139 public async Task<DateTime?> GetNextFreeTime(
bool Reschedule)
141 if (!this.ExecutionTime.HasValue)
144 DateTime TP = this.ExecutionTime.Value;
145 DateTime Now = DateTime.UtcNow;
147 if (!this.Period.HasValue && !
this.BurstInterval.HasValue)
151 if (TP.ToUniversalTime() < Now)
158 await this.Job.ExecutionTimeUpdated(
null);
163 bool Updated =
false;
167 if (this.BurstInterval.HasValue)
169 if (this.BurstCountLeft < this.BurstCount)
170 TP += (this.BurstCount - this.BurstCountLeft) * this.BurstInterval.Value;
173 this.BurstCountLeft > 0 &&
174 TP.ToUniversalTime() < Now)
176 TP += this.BurstInterval.Value;
177 this.BurstCountLeft--;
181 if (TP.ToUniversalTime() >= Now)
184 await this.Job.ExecutionTimeUpdated(TP);
189 if (!this.Period.HasValue ||
this.Period.Value <=
Duration.
Zero)
191 await this.Job.ExecutionTimeUpdated(
null);
195 TP = this.ExecutionTime.Value + this.Period.Value;
196 this.ExecutionTime = TP;
197 this.BurstCountLeft = this.BurstCount;
200 while (TP.ToUniversalTime() < Now);
202 await this.Job.ExecutionTimeUpdated(TP);
207 public async Task ExecuteJob(
object _)
222 await this.Next(
false);
226 public async Task Next(
bool Reschedule)
228 DateTime? Next = await this.GetNextFreeTime(Reschedule);
231 this.ScheduledExecutionTime = scheduler?.
Add(Next.Value,
this.ExecuteJob,
null);
234 this.ScheduledExecutionTime =
null;
238 scheduledJobs.Remove(this.Job.
NodeId);
258 if (
Schedule.ScheduledExecutionTime.HasValue)
261 Schedule.ScheduledExecutionTime =
null;
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
virtual Task LogErrorAsync(string Body)
Logs an error message on the node.
virtual Task< bool > RemoveErrorAsync()
Removes error messages with an empty event ID from the node.
Module that manages the scheduling and execution of jobs.
async Task Start()
Starts the module.
static Scheduler Scheduler
Scheduler used to schedule jobs.
static async Task< bool > Remove(Job Job)
Removes any scheduled activity for the job.
JobScheduler()
Module that manages the scheduling and execution of jobs.
Task Stop()
Stops the module.
static async Task Schedule(Job Job, bool OnlyIfDifferent)
Checks the schedule of a job.
Defines the Jobs data source. This data source contains a tree structure of jobs of nodes
static Root Root
Root node.
Duration? Period
Gets or sets the scheduled execution time of the job.
int BurstCount
Number of executions each period.
Duration? BurstInterval
Gets or sets the scheduled execution time of the job.
DateTime? ExecutionTime
Gets or sets the scheduled execution time of the job.
Task ExecuteJob()
Executes the job.
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Basic access point for runtime language localization.
static async Task< Language > GetDefaultLanguageAsync()
Gets the default language.
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Static class of application-wide semaphores that can be used to order access to editable objects.
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
Class that can be used to schedule events in time. It uses a timer to execute tasks at the appointed ...
bool Remove(DateTime When)
Removes an event scheduled for a given point in time.
void Dispose()
IDisposable.Dispose
DateTime Add(DateTime When, Action< object > Callback, object State)
Adds an event.
Interface for late-bound modules loaded at runtime.
Interface for nodes that are published through the concentrator interface.
Represents a duration value, as defined by the xsd:duration data type: http://www....
static readonly Duration Zero
Zero value