Exemple #1
0
 protected virtual void ConstructEndpoints()
 {
     this.AuthenticationService = new AuthenticationService(this);
     this.projectsService       = new ProjectsService(this);
     this.ActivityService       = new ActivityService(this);
     this.TaskLogService        = new TaskLogService(this);
     this.Users    = new UserEndpoint(this);
     this.Projects = new ProjectEndpoint(this);
     this.Tasks    = new TaskEndpoint(this);
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="job"></param>
        private void JobExecute(Job job)
        {
            var logService = new TaskLogService(this);

            var jobExecuter = new JobExecuter(job);

            jobExecuter.Container.Register <ITaskLogService>(logService);
            jobExecuter.Container.Register <ITaskCustomizedLogService>(new TaskCustomizedLogService(this));
            jobExecuter.Initialize();
            jobExecuter.TaskExecuted += executer => logService.Information(Environment.NewLine);

            DisableComponents();
            ThreadTask.Run(() => jobExecuter.Execute()).ContinueWith(OnExecuteFinished);
        }
        public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            try
            {
                //DateTime? NextFireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.NextFireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
                //DateTime? FireTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(context.FireTimeUtc.Value.DateTime, TimeZoneInfo.Local);
                DateTime?NextFireTimeUtc = null;
                if (context.NextFireTimeUtc.HasValue)
                {
                    NextFireTimeUtc = context.NextFireTimeUtc.Value.DateTime;
                }
                DateTime?FireTimeUtc = null;
                if (context.NextFireTimeUtc.HasValue)
                {
                    FireTimeUtc = context.FireTimeUtc.Value.DateTime;
                }

                double TotalSeconds = context.JobRunTime.TotalSeconds;

                TB_TM_TaskInfo taskInfo   = null;
                string         LogContent = string.Empty;
                if (context.MergedJobDataMap != null)
                {
                    if (context.MergedJobDataMap.ContainsKey("TaskInfo"))
                    {
                        taskInfo = JsonConvert.DeserializeObject <TB_TM_TaskInfo>(context.MergedJobDataMap.GetString("TaskInfo"));
                    }

                    if (taskInfo != null)
                    {
                        System.Text.StringBuilder log = new System.Text.StringBuilder();
                        int i = 0;
                        foreach (var item in context.MergedJobDataMap)
                        {
                            string key = item.Key;
                            if (key.StartsWith("Extend_"))
                            {
                                if (i > 0)
                                {
                                    log.Append(",");
                                }
                                log.AppendFormat("{0}:{1}", item.Key, item.Value);
                                i++;
                            }
                        }
                        if (i > 0)
                        {
                            LogContent = string.Concat("[", log.ToString(), "]");
                        }
                        TaskInfoService _TaskInfoService = new TaskInfoService();
                        TaskLogService  _TaskLogService  = new TaskLogService();
                        taskInfo             = _TaskInfoService.GetModel(taskInfo.TaskId);
                        taskInfo.LastRunTime = FireTimeUtc;
                        taskInfo.NextRunTime = NextFireTimeUtc;
                        taskInfo.RunCount    = taskInfo.RunCount + 1;
                        if (taskInfo.ImmedRun == 1)//立刻运行
                        {
                            LogContent        = "(本次是立刻运行)" + LogContent;
                            taskInfo.ImmedRun = 0;
                        }

                        _TaskInfoService.Update(taskInfo);
                        _TaskLogService.Add(new TaskManager.Core.Model.TB_TM_TaskLog()
                        {
                            TaskId            = taskInfo.TaskId,
                            TaskName          = taskInfo.TaskName,
                            CreatedDateTime   = DateTime.Now,
                            ExecutionTime     = FireTimeUtc,
                            ExecutionDuration = TotalSeconds,
                            RunLog            = LogContent
                        });
                    }
                }
                //if (jobException != null)
                //{
                //    LogContent = LogContent + " EX:" + jobException.ToString();
                //    new TaskLogService().Add(new TaskManager.Core.Model.TB_TM_TaskLog()
                //    {
                //        TaskId = Convert.ToInt32(TaskId),
                //        TaskName = TaskName,
                //        CreatedDateTime = DateTime.Now,
                //        ExecutionTime = FireTimeUtc,
                //        ExecutionDuration = TotalSeconds,
                //        RunLog = LogContent
                //    });
                //}
            }
            catch (Exception ex)
            {
                //错误日志
            }
        }
Exemple #4
0
 public RecurringJobBase()
 {
     _taskLogService = new TaskLogService();
 }
Exemple #5
0
 public TaskLogController()
 {
     _TaskLogService = new TaskLogService();
 }