Пример #1
0
 internal ScheduleCrashException(string message, ScheduledTask task, Exception innerException)
     : base(message, innerException)
 {
     Task = task;
     Data["TaskName"] = task.Name;
     Data["Schedule"] = task.Schedule.OriginalText;
 }
Пример #2
0
        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));
        }
Пример #3
0
 internal PendingEvent(DateTimeOffset scheduledTime, ScheduledTask task, int runId)
 {
     ScheduledTime = scheduledTime;
     Task = task;
     RunId = runId;
 }
Пример #4
0
 public bool TryGetTask(string name, out ScheduledTask task)
 {
     return _tasks.TryGetValue(name, out task);
 }
Пример #5
0
        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;
            }
        }
Пример #6
0
        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;
        }
Пример #7
0
 private void TaskOnOnException(ScheduledTask task, Exception ex)
 {
     var ev = OnTaskException;
     ev?.Invoke(task, ex);
 }
 public TaskExceptionEventArgs(ScheduledTask scheduledTask, Exception exception)
 {
     Task = scheduledTask;
     Exception = exception;
 }
Пример #9
0
 public bool TryGetTask(string name, out ScheduledTask task)
 {
     return(_tasks.TryGetValue(name, out task));
 }
Пример #10
0
        void TaskOnOnException(ScheduledTask task, Exception ex)
        {
            var ev = OnTaskException;

            ev?.Invoke(task, ex);
        }
Пример #11
0
 internal PendingEvent(DateTimeOffset scheduledTime, ScheduledTask task, int runId)
 {
     ScheduledTime = scheduledTime;
     Task          = task;
     RunId         = runId;
 }
Пример #12
0
 internal ScheduleCrashException(string message, ScheduledTask task, Exception innerException) : base(message, innerException)
 {
     Task             = task;
     Data["TaskName"] = task.Name;
     Data["Schedule"] = task.Schedule.OriginalText;
 }