Exemplo n.º 1
0
        public virtual async Task <TimeSpan> RunJobAsync(Job job, SilenceTime silence)
        {
            //estimate report generation time to correct interval between runnings
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Log log = await ExecuteRuleAsync(job);

            job.WriteSelfTo(log);

            bool success = log.StatusEnum == StatusEnum.Success;

            if (!success || job.LogSuccess)
            {
                await LogRepository.SaveAsync(log);
            }

            if (!success)
            {
                await ExecuteTriggersAsync(job, silence, log);
            }

            stopwatch.Stop();

            return(stopwatch.Elapsed);
        }
Exemplo n.º 2
0
        private async Task ExecuteTriggersAsync(Job job, SilenceTime silence, Log log)
        {
            try
            {
                if (silence.IsSilenceNow(log.DateTime))
                {
                    Trace.WriteLine("Start triggers for a job: " + job.Name);

                    silence.SetUntil(log.DateTime + job.FailureSilenceInterval);

                    var tasks = new List <Task>();

                    foreach (var trigger in job.GetTriggers())
                    {
                        tasks.Add(trigger.ExecuteAsync(log, silence));
                    }

                    await Task.WhenAll(tasks);

                    silence.ResetCounter();
                }
                else
                {
                    Trace.WriteLine("Mute triggers for a job: " + job.Name);
                    silence.IncreaseCounter();
                }
            }
            catch (Exception exception)
            {
                await SystemLogRepository.SaveAsync(exception, $"Unhandled trigger error. Job = [{job.Name}].");
            }
        }
Exemplo n.º 3
0
		public virtual async Task<TimeSpan> RunJobAsync(Job job, SilenceTime silence)
		{
			//estimate report generation time to correct interval between runnings
			var stopwatch = new Stopwatch();
			stopwatch.Start();

			Log log = await ExecuteRuleAsync(job);

			job.WriteSelfTo(log);

			bool success = log.StatusEnum == StatusEnum.Success;

			if (!success || job.LogSuccess) await LogRepository.SaveAsync(log);

			if (!success) await ExecuteTriggersAsync(job, silence, log);

			stopwatch.Stop();

			return stopwatch.Elapsed;
		}
Exemplo n.º 4
0
		public async Task RunCycleAsync(Job job)
		{
			var silence = new SilenceTime();

			while (true)
			{
				try
				{
					var elapsed = await RunJobAsync(job, silence);

					await CoreEx.DelayIfNeeded(job.CheckInterval, elapsed);
				}
				catch (Exception exception)
				{
					var minutes = TimeSpan.FromMinutes(10);

					await SystemLogRepository.SaveAsync(exception, 
						$"Unhandled job error. Job = [{job.Name}]. Job will be recycled in {minutes}. ");

					await Task.Delay(minutes); //TODO to config
				}
			}
		}
Exemplo n.º 5
0
        public async Task RunCycleAsync(Job job)
        {
            var silence = new SilenceTime();

            while (true)
            {
                try
                {
                    var elapsed = await RunJobAsync(job, silence);

                    await CoreEx.DelayIfNeeded(job.CheckInterval, elapsed);
                }
                catch (Exception exception)
                {
                    var minutes = TimeSpan.FromMinutes(10);

                    await SystemLogRepository.SaveAsync(exception,
                                                        $"Unhandled job error. Job = [{job.Name}]. Job will be recycled in {minutes}. ");

                    await Task.Delay(minutes);                     //TODO to config
                }
            }
        }
Exemplo n.º 6
0
		private async Task ExecuteTriggersAsync(Job job, SilenceTime silence, Log log)
		{
			try
			{
				if (silence.IsSilenceNow(log.DateTime))
				{
					Trace.WriteLine("Start triggers for a job: " + job.Name);

					silence.SetUntil(log.DateTime + job.FailureSilenceInterval);

					var tasks = new List<Task>();

					foreach (var trigger in job.GetTriggers())
					{
						tasks.Add(trigger.ExecuteAsync(log, silence));
					}

					await Task.WhenAll(tasks);

					silence.ResetCounter();
				}
				else
				{
					Trace.WriteLine("Mute triggers for a job: " + job.Name);
					silence.IncreaseCounter();
				}
			}
			catch (Exception exception)
			{
				await SystemLogRepository.SaveAsync(exception, $"Unhandled trigger error. Job = [{job.Name}].");
			}
		}