public async Task Start() { logger.LogInformation("Starting EzBus"); await taskRunner.Run <IStartupTask>(); logger.LogInformation("EzBus started"); }
public static ITask Forever( this ITaskRunner runner , Action action , bool start = true ) { return(runner.Run(_Forever(action), start)); }
public async Task ExecuteJob(JobDto jobQueue) { using (_logger.BeginScope(new JobScope(jobQueue.ProjectId, jobQueue.Id))) { try { _logger.LogInformation($"Executing job queue {jobQueue.Code}."); var jobTasks = await _jobDefinitionService.GetJobTaskDefinitions(jobQueue.ProjectId, jobQueue.JobDefinitionId ?? 0); var workingLocation = Path.Combine(_engineConfig.WorkingLocation, jobQueue.Code); var result = await _taskRunner.Run(jobQueue.ProjectId, jobQueue, jobTasks, _engineConfig.TaskProvidersLocation, workingLocation); if (result.Values.Any(t => t.IsSuccess && t.StopTheProcess)) { jobQueue.Status = JobStatus.Pending; } else if (result.Values.Any(t => !t.IsSuccess)) { jobQueue.Status = JobStatus.Error; } else { jobQueue.Status = JobStatus.Completed; } } catch (Exception ex) { _logger.LogError(ex, ex.Message); jobQueue.Status = JobStatus.Error; } await _jobQueueService.UpdateJobQueue(jobQueue.Id, new UpdateJobDto { Id = jobQueue.Id, CatapultEngineId = jobQueue.CatapultEngineId, CatapultEngineIPAddress = jobQueue.CatapultEngineIPAddress, CatapultEngineMachineName = jobQueue.CatapultEngineMachineName, CatapultEngineVersion = jobQueue.CatapultEngineVersion, JobType = jobQueue.JobType, Status = jobQueue.Status, JobTasksStatus = jobQueue.JobTasksStatus, OutputValues = jobQueue.OutputValues }); await _jobLogWriter.EndJobLog(jobQueue.Id); await _jobQueueService.SendNotification(jobQueue.Id); if (jobQueue.Status == JobStatus.Completed && jobQueue.IsDeletion && jobQueue.ProjectStatus == ProjectStatusFilterType.Deleting) { _logger.LogInformation($"Deleting project {jobQueue.ProjectId}"); await _projectService.DeleteProjectByEngine(jobQueue.ProjectId); } } }
public void Set(StatusType status, string text) { _runner.Run( () => { State = status.Translate(); Text = text; }); }
public BarResponse Execute(BarRequest request) { var result = _taskRunner.Run(); return(new BarResponse() { Code = result ? "Ok" : "Error" }); }
private void DispatchToAsynchronousSubscribers( IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) { _taskRunner.Run( Label.Named("publish-to-asynchronous-subscribers"), (r, c) => Task.WhenAll(domainEvents.Select(d => DispatchToSubscribersAsync(d, r, SubscribeAsynchronousToType, true, c))), cancellationToken); }
public static ITask Schedule( this ITaskRunner runner , float t , Action action ) { return(runner.Run( _Schedule(t, action: action) )); }
public static ITask While( this ITaskRunner runner , Func <bool> condition , Action action , Action then = null , bool start = true ) { return(runner.Run(_While(condition, action, then), start)); }
public static ITask When( this ITaskRunner runner , Func <bool> condition , Action action ) { return(runner.Run( _When(condition, action: action) )); }
public List <LogItem> Run() { Log log; try { log = _coffeeMakerUtil.Run(); } catch (Exception exception) { throw new Exception("Unable to run process: " + exception.Message); } return(log?.Get()); }
public static ITask Run( this ITaskRunner runner , ref ITask task , IEnumerator enumerator ) { if (task != null && task.IsRunning()) { task.Cancel(); } task = runner.Run(enumerator); return(task); }
public virtual bool Run() { return(_taskRunner.Run()); }
public virtual async Task Start() { try { await this.Stop(); } catch (Exception ex) { await Utility.CreateLogger(nameof(NanoServiceBase), nameof(Start)).Code(911).Error(ex).SaveAsync(); } CancellationToken token = this._cancellation.Token; //the Execute method will be called below so if a derived type does not use the cancellationToken then this will be the default behaviour. try { token.Register(() => { this.IsRunning = false; this.Notify("The service is cancelling."); this.OnStateChangedSafely(ServiceState.Cancelling); }); } catch (Exception) { this.IsRunning = false; this.Notify("An exception occurred while cancelling."); this.OnStateChangedSafely(ServiceState.ErrorOccuredWhenCancelling); } this.Notify("The service is startting."); this.OnStateChangedSafely(ServiceState.Starting); this.IsRunning = true; this.ExecutedOperationCount = -1; ExceptionCounter exceptionCounter = new ExceptionCounter(this.MaxErrorLimit < 1 ? int.MaxValue : this.MaxErrorLimit);//Burası Konfigure edilebilir. ITaskRunner runner = this.CreateTaskRunner(); while (this.Continue()) { try { await runner.Run(this.Execute, this.Observer, token); } catch (Exception ex) { await Utility.CreateLogger(nameof(NanoServiceBase), nameof(Start)).Code(911).Error(ex).SaveAsync(); if (exceptionCounter.CheckIfMaxExceptionOccur(ex)) { this.IsRunning = false; this.OnStateChangedSafely(ServiceState.FailedDueToMaxErrorExceed); string msg = $"{this.GetType()} has been stopped due to {(this.MaxErrorLimit < 2 ? "an exception" : "a repeated exception.")}"; this.Notify(msg); await Utility.CreateLogger(nameof(NanoServiceBase), nameof(Start)).Code(913).Warning(msg).SaveAsync(); } } await Wait(this.Interval.TotalMilliseconds.ConvertTo <int>()); } this.IsRunning = false; //her iştimale karşı. örneğin CompletedDueToMaxOperationLimit' de. if (this._currentState == ServiceState.Starting) //yani herhangi bir nedenden durmamış. örneğin once seçilip çalıştırılıp tamamlanmış. { this.Notify("The service has been completed due to max operation limit."); this.OnStateChangedSafely(ServiceState.CompletedDueToMaxOperationLimit); } //else//Stop dan dolayı yapılmışsa burası zaten çalışıyor. CompletedDueToMaxOperationLimit ve FailedDueToMaxErrorExceed ise zastop edilmeden durmuş oluyor servis zaten. //{ // this.Notify("The Service has been stopped."); // this.OnStateChangedSafely(ServiceState.Stopped); //} }
/// <summary> /// 运行任务 /// </summary> public void Run() { try { var files = Directory.EnumerateFiles(AppPath); files = files.Where(n => Path.GetExtension(n).ToLower() == ".dll"); List <Assembly> mainAssembly = new List <Assembly>(); foreach (var item in files) { Assembly assembly = Assembly.LoadFile(item); Type[] astypes = assembly.GetTypes(); if (astypes.Any(n => n.BaseType == typeof(TaskRunner))) { mainAssembly.Add(assembly); } } if (mainAssembly.Count == 0) { throw new Exception("没有找到继承于ITaskRunner的类型"); } if (mainAssembly.Count > 1) { throw new Exception("找到多个存在继承于ITaskRunner的类型的程序集"); } Type[] types = mainAssembly[0].GetTypes().Where(n => typeof(ITaskRunner).IsAssignableFrom(n)).ToArray(); if (types.Length > 1) { throw new Exception("找到多个存在继承于ITaskRunner的类型"); } _runner = System.Activator.CreateInstance(types[0]) as ITaskRunner; if (_runner == null) { throw new Exception("实例化对象失败"); } //创建日志队列线程 Thread thread = new Thread(() => ExecLogQuenuen(_runner)); thread.Start(); //创建命令接送线程 thread = new Thread(CommandListen); thread.Start(); try { SendLog(new LogInfo { Level = LogLevel.Info, Message = "【开始执行】", WriteTime = DateTime.Now }); _runner.Running = true; _runner.Run(AppId); SendLog(new LogInfo { Level = LogLevel.Info, Message = "【执行结束并退出】", WriteTime = DateTime.Now }); } catch (Exception ex) { SendLog(new LogInfo { Level = LogLevel.Error, Message = "【异常退出】" + ex.Message + ex.StackTrace, WriteTime = DateTime.Now }); } } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); SendLog(new LogInfo { Level = LogLevel.Error, Message = ex.Message + ex.StackTrace, WriteTime = DateTime.Now }); } //结束时把队列中的任务发送完 if (_runner != null) { SendQuenuenLog(_runner); } }
//[ResponseType(bool)] public IHttpActionResult Get() { return(Ok(new { success = _taskRunner.Run() })); }
public void SendInquiryRecievedMessage(Inquiry inquiry) { _taskRunner.Run <IMessageService>(x => x.SendInquiryRecievedMessage(inquiry)); }
async Task IEventHandler <ApplicationActionEvent> .HandleAsync(ApplicationActionEvent @event) { _runner.Run(() => _queue.QueueTask(() => HandleActionAsync(@event.Action))); await Task.Yield(); }