Exemplo n.º 1
0
        private async Task Create(ExecutionHistoryEntry entry)
        {
            if (_data.Count >= 500)
            {
                await Purge(entry.SchedulerName);
            }

            lock (_data)
            {
                _data.Add(entry);
            }
        }
        public async Task <IEnumerable <ExecutionHistoryEntry> > FilterLast(string schedulerName, int limit, CancellationToken cancellationToken = default)
        {
            //return await Task.FromResult(new List<ExecutionHistoryEntry>());
            List <ExecutionHistoryEntry> list = new List <ExecutionHistoryEntry>();

            using (ConnectionAndTransactionHolder dbConnection = GetConnection(IsolationLevel.ReadUncommitted))
            {
                string sql = string.Format(PropertySqlServerSelectHistory, _tablePrefix);

                if (_provider.Equals("MySql"))
                {
                    sql = string.Format(PropertyMySqlSelectHistory, _tablePrefix);
                }

                using (DbCommand dbCommand = Delegate.PrepareCommand(dbConnection, sql))
                {
                    Delegate.AddCommandParameter(dbCommand, "schedulerName", schedulerName);

                    Delegate.AddCommandParameter(dbCommand, "limit", limit);

                    using (DbDataReader reader = await dbCommand.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false))
                    {
                        while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                        {
                            var entry = new ExecutionHistoryEntry
                            {
                                Recovering           = Delegate.GetBooleanFromDbValue(reader["Recovering"]),
                                Vetoed               = Delegate.GetBooleanFromDbValue(reader["Vetoed"]),
                                ActualFireTimeUtc    = Convert.ToDateTime(reader["Actual_Fire_Time_Utc"]),
                                FinishedTimeUtc      = Convert.ToDateTime(reader["Finished_Time_Utc"]),
                                FireInstanceId       = reader.GetString("Fire_Instance_Id"),
                                ScheduledFireTimeUtc = Convert.ToDateTime(reader["Scheduled_Fire_Time_Utc"]),
                                SchedulerInstanceId  = reader.GetString("Scheduler_Instance_Id"),
                                SchedulerName        = reader.GetString("SCHED_NAME"),
                                JobName              = reader.GetString("JOB_NAME"),
                                JobGroup             = reader.GetString("JOB_GROUP"),
                                TriggerName          = reader.GetString("TRIGGER_NAME"),
                                TriggerGroup         = reader.GetString("TRIGGER_GROUP"),
                                FiredTime            = Delegate.GetDateTimeFromDbValue(reader["FIRED_TIME"]).GetValueOrDefault(),
                                ScheduledTime        = Delegate.GetDateTimeFromDbValue(reader["SCHED_TIME"]).GetValueOrDefault(),
                                RunTime              = Delegate.GetTimeSpanFromDbValue(reader["RUN_TIME"]).GetValueOrDefault(),
                                Error        = Delegate.GetBooleanFromDbValue(reader["ERROR"]),
                                ErrorMessage = reader.GetString("ERROR_MESSAGE")
                            };
                            list.Add(entry);
                        }
                    }
                }
            }
            list.Reverse();
            return(list);
        }
Exemplo n.º 3
0
        //DateTime _nextPurgeTime = DateTime.UtcNow;
        //private int _updatesFromLastPurge;

        //private Dictionary<string, long> totalJobsExecutedDic = new Dictionary<string, long>();
        //private Dictionary<string, long> totalJobsFailedDic = new Dictionary<string, long>();
        //private long _totalJobsExecuted = 0;
        //private long _totalJobsFailed = 0;

        //public string SchedulerName { get; set; }

        /// <summary>
        /// 创建执行任务历史记录
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task CreateJobHistoryEntry(IJobExecutionContext context, CancellationToken cancellationToken)
        {
            var entry = new ExecutionHistoryEntry()
            {
                FireInstanceId       = context.FireInstanceId,
                SchedulerInstanceId  = context.Scheduler.SchedulerInstanceId,
                SchedulerName        = context.Scheduler.SchedulerName,
                ActualFireTimeUtc    = context.FireTimeUtc.UtcDateTime,
                ScheduledFireTimeUtc = context.ScheduledFireTimeUtc?.UtcDateTime,
                Recovering           = context.Recovering,
                JobName     = context.JobDetail.Key.ToString(),
                TriggerName = context.Trigger.Key.ToString(),
            };

            await Create(entry);
        }
        public async Task <PagedResultDto <ExecutionHistoryEntry> > GetPageJobHistoryEntries(
            string schedulerName,
            int pageIndex, int pageSize,
            string orderByStr,
            CancellationToken cancellationToken = default)
        {
            var pageResult = new PagedResultDto <ExecutionHistoryEntry>();

            using (ConnectionAndTransactionHolder dbConnection = GetConnection(IsolationLevel.ReadUncommitted))
            {
                //string sql = AdoJobStoreUtil.ReplaceTablePrefix(PropertySqlServerSelectHistoryEntry, _tablePrefix, null);

                string sql = string.Format(PropertySqlServerSelectHistoryEntryPage, _tablePrefix, orderByStr);

                if (_provider.Equals("MySql"))
                {
                    //sql = AdoJobStoreUtil.ReplaceTablePrefix(PropertyMySqlSelectHistoryEntry, _tablePrefix, null);
                    sql = string.Format(PropertyMySqlSelectHistoryEntryPage, _tablePrefix, orderByStr);
                }

                pageResult.TotalCount = await GetAllCount(schedulerName, cancellationToken);

                using (DbCommand dbCommand = Delegate.PrepareCommand(dbConnection, sql))
                {
                    int page = pageIndex > 1 ? (pageIndex - 1) * pageSize : 0;

                    Delegate.AddCommandParameter(dbCommand, "schedulerName", schedulerName);
                    Delegate.AddCommandParameter(dbCommand, "page", page);

                    if (_provider.Equals("MySql"))
                    {
                        // pageSize
                        Delegate.AddCommandParameter(dbCommand, "pageSize", pageSize);
                    }
                    else
                    {
                        // endPage
                        Delegate.AddCommandParameter(dbCommand, "endPage", page + pageSize);
                    }

                    using (DbDataReader reader = await dbCommand.ExecuteReaderAsync(cancellationToken).ConfigureAwait(false))
                    {
                        List <ExecutionHistoryEntry> list = new List <ExecutionHistoryEntry>();
                        while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
                        {
                            var entry = new ExecutionHistoryEntry
                            {
                                Recovering           = Delegate.GetBooleanFromDbValue(reader["Recovering"]),
                                Vetoed               = Delegate.GetBooleanFromDbValue(reader["Vetoed"]),
                                ActualFireTimeUtc    = Convert.ToDateTime(reader["Actual_Fire_Time_Utc"]),
                                FinishedTimeUtc      = Convert.ToDateTime(reader["Finished_Time_Utc"]),
                                FireInstanceId       = reader.GetString("Fire_Instance_Id"),
                                ScheduledFireTimeUtc = Convert.ToDateTime(reader["Scheduled_Fire_Time_Utc"]),
                                SchedulerInstanceId  = reader.GetString("Scheduler_Instance_Id"),
                                SchedulerName        = reader.GetString("SCHED_NAME"),
                                JobName              = reader.GetString("JOB_NAME"),
                                JobGroup             = reader.GetString("JOB_GROUP"),
                                TriggerName          = reader.GetString("TRIGGER_NAME"),
                                TriggerGroup         = reader.GetString("TRIGGER_GROUP"),
                                FiredTime            = Delegate.GetDateTimeFromDbValue(reader["FIRED_TIME"]).GetValueOrDefault(),
                                ScheduledTime        = Delegate.GetDateTimeFromDbValue(reader["SCHED_TIME"]).GetValueOrDefault(),
                                RunTime              = Delegate.GetTimeSpanFromDbValue(reader["RUN_TIME"]).GetValueOrDefault(),
                                Error        = Delegate.GetBooleanFromDbValue(reader["ERROR"]),
                                ErrorMessage = reader.GetString("ERROR_MESSAGE")
                            };
                            list.Add(entry);
                        }
                        pageResult.Items = list.AsReadOnly();
                    }
                }
            }
            return(pageResult);
        }