Beispiel #1
0
        /// <summary>
        /// Add a job to the runner.
        /// </summary>
        /// <param name="job.Name"></param>
        /// <param name="job"></param>
        public void Add(Job job)
        {
            _eventContext.JobRegistered(job);

            // Add the job to the job list.
            Jobs.Add(job.Name, job);

            // Store the event context in the job, so it can also send events.
            job.EventContext = _eventContext;
        }
Beispiel #2
0
        /// <summary>
        /// Initialize every job.
        /// </summary>
        private void InitializeJobs(Job[] jobs)
        {
            JobsEventSource.Log.JobHostInitializing(jobs.Count());

            // Initialize every job.
            foreach (var job in jobs)
            {
                try
                {
                    JobsEventSource.Log.JobInitializing(job.Name);

                    job.Initialize();

                    JobsEventSource.Log.JobInitialized(job.Name);
                }
                catch (Exception ex)
                {
                    JobsEventSource.Log.JobInitializationError(job.Name, ex.GetType().Name, ex.Message, ex.StackTrace);
                    throw;
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Add a job to the runner.
 /// </summary>
 /// <param name="job"></param>
 public void Add(Job job)
 {
     Jobs.Add(job.Name, job);
 }
Beispiel #4
0
        /// <summary>
        /// Run a single job.
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="job"></param>
        private void RunJob(string jobName, Job job)
        {
            JobsEventSource.Log.JobExecuting(jobName);

            try
            {
                job.RunOnce();
            }
            catch (Exception ex)
            {
                JobsEventSource.Log.JobExecutionError(jobName, ex.GetType().Name, ex.Message, ex.StackTrace);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Schedule a single job.
        /// </summary>
        /// <param name="jobType"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        private IDisposable ScheduleJob(string jobType, Job job)
        {
            var startTime = DateTimeOffset.UtcNow + job.StartOffset;

            // Log.
            JobsEventSource.Log.JobScheduling(jobType, job.Interval.ToString(), startTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"));

            // Create an infinite loop.
            return Observable.Timer(startTime, job.Interval).Subscribe(_ => RunJob(jobType, job));
        }
 public void JobRegistered(Job job)
 {
     
 }
 public void TaskFailed(Job job, JobTask task, DateTime startTime, Exception exception)
 {
     
 }
 public void TaskComplete(Job job, JobTask task, DateTime startTime, TimeSpan duration)
 {
     
 }
 public void TaskProgress(Job job, JobTask task, string message, object[] args)
 {
     
 }
 public void TaskRunning(Job job, JobTask task, DateTime startTime)
 {
     
 }
 public void JobFailed(Job job, DateTime startTime, Exception exception)
 {
     
 }
 public void JobComplete(Job job, DateTime startTime, TimeSpan duration)
 {
     
 }
 public void JobRunning(Job job, DateTime startTime)
 {
     
 }
Beispiel #14
0
        /// <summary>
        /// Run a single job.
        /// </summary>
        /// <param name="job"></param>
        private void RunJob(Job job)
        {
            var runId = Guid.NewGuid();
            var startTime = DateTime.UtcNow;

            try
            {
                job.CancellationToken = CancellationToken.Token;
                job.RunId = runId;

                // Log start.
                EngineEventSource.Log.Info("Running job '{0}' at {1}.", job.Name, startTime);

                // Notify event.
                _eventContext.JobRunning(job, startTime);

                // Execute the job.
                job.Run();

                // Total duration.
                var duration = (DateTime.UtcNow - startTime);

                // Notify event.
                _eventContext.JobComplete(job, startTime, duration);

                // Log end.
                EngineEventSource.Log.Info("Job run complete for '{0}' in {1}.", job.Name, duration);
            }
            catch (Exception ex)
            {
                // Notify event.
                _eventContext.JobFailed(job, startTime, ex);

                // Log.
                EngineEventSource.Log.ErrorDetails(ex, "Error running job '{0}'.", job.Name);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Schedule a single job.
        /// </summary>
        /// <param name="job.Name"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        private IDisposable ScheduleJob(Job job)
        {
            var startTime = DateTimeOffset.UtcNow + job.StartOffset;

            // Log.
            EngineEventSource.Log.Info("Scheduled job '{0}' to run every {1} (starting: {2}).",
                job.Name, job.Interval, job.StartOffset);

            // Create an infinite loop.
            return Observable.Timer(startTime, job.Interval).Subscribe(_ => RunJob(job));
        }