internal ScheduleCrashException(string message, ScheduledTask task, Exception innerException) : base(message, innerException) { Task = task; Data["TaskName"] = task.Name; Data["Schedule"] = task.Schedule.OriginalText; }
private void ScheduledTask_OnException(ScheduledTask task, Exception exception) { string message = $"An error occurred while executing {task.Name}"; WorkerLogger.Error(message, exception); Store($"{message}, Exception = {exception.Message}"); OnTaskException?.Invoke(this, new TaskExceptionEventArgs(task, exception)); }
internal PendingEvent(DateTimeOffset scheduledTime, ScheduledTask task, int runId) { ScheduledTime = scheduledTime; Task = task; RunId = runId; }
public bool TryGetTask(string name, out ScheduledTask task) { return _tasks.TryGetValue(name, out task); }
public ScheduledTask[] GetAllTasks() { lock (_lockTasks) { // could be one line of linq, but eh, this is cheaper var tasks = new ScheduledTask[_tasks.Count]; var i = 0; foreach(var t in _tasks) { tasks[i] = t.Value; i++; } return tasks; } }
private ScheduledTask AddTaskImpl( string name, Schedule schedule, ScheduledTaskCallback callback, ScheduledTaskAsyncCallback asyncCallback, bool autoRun, DateTimeOffset lastKnownEvent, TimeSpan window) { if (schedule == null) throw new ArgumentNullException(nameof(schedule)); if (name == null) name = Guid.NewGuid().ToString(); ScheduledTask task; lock (_lockTasks) { if (IsShuttingDown) throw new Exception("Cannot add a task to Schtick after Shutdown() has been called."); if (_tasks.ContainsKey(name)) throw new Exception($"A scheduled task named \"{name}\" already exists."); task = new ScheduledTask(this, name, schedule, callback, asyncCallback) { Window = window, IsAttached = true, }; _tasks.Add(name, task); } task.OnException += TaskOnOnException; if (autoRun) task.StartSchedule(lastKnownEvent); return task; }
private void TaskOnOnException(ScheduledTask task, Exception ex) { var ev = OnTaskException; ev?.Invoke(task, ex); }
public TaskExceptionEventArgs(ScheduledTask scheduledTask, Exception exception) { Task = scheduledTask; Exception = exception; }
public bool TryGetTask(string name, out ScheduledTask task) { return(_tasks.TryGetValue(name, out task)); }
void TaskOnOnException(ScheduledTask task, Exception ex) { var ev = OnTaskException; ev?.Invoke(task, ex); }