public async Task Error(string msg) { if (!_options.EnabledLogger) { return; } var entity = new JobLogEntity { JobId = JobId, Type = JobLogType.Error, Msg = msg, CreatedTime = DateTime.Now }; await _repository.AddAsync(entity); }
public async Task Error(string msg) { var config = _configProvider.Get <QuartzConfig>(); if (!config.Logger) { return; } var entity = new JobLogEntity { JobId = JobId, Type = JobLogType.Error, Msg = msg, CreatedTime = DateTime.Now }; await _repository.AddAsync(entity); }
/// <summary> /// 更新Job执行结果(插入日志,更新上次/下次执行时间,执行次数)(事务) /// </summary> /// <param name="nextFireTime">下次执行时间</param> /// <param name="logEntity">JobLog实体</param> /// <returns>是否成功</returns> public bool UpdateJobFireResult(DateTime nextFireTime, JobLogEntity logEntity) { int r = 0; using (TransactionScope trans = TransactionScopeBuilder.CreateReadCommitted(false)) { JobInfoEntity job = _jobRepository.Get(logEntity.JobId); r = _jobRepository.Update(logEntity.JobId, new List <DbUpdate <JobInfoEntity> > { new DbUpdate <JobInfoEntity>(j => j.LastFireTime, logEntity.FireTime), new DbUpdate <JobInfoEntity>(j => j.NextFireTime, nextFireTime), new DbUpdate <JobInfoEntity>(j => j.FireCount, job.FireCount + 1) }); r += _logRepository.Insert(logEntity) > 0 ? 1 : 0; if (r >= 2) { trans.Complete(); } } return(r >= 2); }
public static bool UpdateJobStatus(long jobId, DateTime lastRunTime, DateTime nextRunTime, double executionDuration, string runLog) { bool isSuccess = false; using (TransactionScope trans = new TransactionScope()) { isSuccess = UpdateJobStatus(jobId, lastRunTime, nextRunTime); JobLogEntity log = new JobLogEntity { JobId = jobId, CreateTime = DateTime.Now, ExecutionDuration = executionDuration, ExecutionTime = lastRunTime, RunLog = runLog }; isSuccess = AddLog(log); if (isSuccess) { trans.Complete(); } } return(isSuccess); }
/// <summary> /// 插入一条JobLog /// </summary> /// <param name="logEntity">JobLog实体</param> /// <returns>是否成功</returns> public bool InsertLog(JobLogEntity logEntity) { return(_logRepository.Insert(logEntity) > 0); }
public static bool AddLog(JobLogEntity jobLog) { return(_logRepository.Insert(jobLog) > 0); }
public static async Task <bool> UpdateJobFireResultAsync(DateTime nextFireTime, JobLogEntity logEntity) { int r = 0; using (TransactionScope trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { JobInfoEntity job = await _jobRepository.GetAsync(logEntity.JobId); r = await _jobRepository.UpdateAsync(logEntity.JobId, new List <DbUpdate <JobInfoEntity> > { new DbUpdate <JobInfoEntity>(j => j.LastFireTime, logEntity.FireTime), new DbUpdate <JobInfoEntity>(j => j.NextFireTime, nextFireTime), new DbUpdate <JobInfoEntity>(j => j.FireCount, job.FireCount + 1) }); r += await _logRepository.InsertAsync(logEntity) > 0 ? 1 : 0; if (r >= 2) { trans.Complete(); } } return(r >= 2); }
public static async Task <bool> InsertLogAsync(JobLogEntity logEntity) { return(await _logRepository.InsertAsync(logEntity) > 0); }
private void LogJob(string jobId) { try { JobInfo jobInfo = null; using (var conn = new SqlConnection(_connectionString)) { conn.Open(); try { using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GetJobDetail"; cmd.Parameters.AddWithValue("jobId", jobId); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { jobInfo = new JobInfo(reader.GetString(0), reader.GetString(1)); jobInfo.JobType = (JobType)reader.GetInt32(2); jobInfo.Status = (JobStatus)reader.GetInt32(3); jobInfo.StatusMessage = reader.IsDBNull(4) ? String.Empty : reader.GetString(4); jobInfo.ScheduledRunTime = reader.IsDBNull(5) ? (DateTime?)null : reader.GetDateTime(5); jobInfo.StartTime = reader.IsDBNull(6) ? (DateTime?)null : reader.GetDateTime(6); jobInfo.ProcessorId = reader.IsDBNull(7) ? String.Empty : reader.GetString(7); jobInfo.ProcessingCompleted = reader.IsDBNull(8) ? (DateTime?)null : reader.GetDateTime(8); jobInfo.ProcessingException = reader.IsDBNull(9) ? String.Empty : reader.GetString(9); jobInfo.RetryCount = reader.GetInt32(10); } } } } catch (Exception ex) { Trace.TraceError("Error retrieving job detail for job {0}. Cause: {1}", jobId, ex); } finally { conn.Close(); } } if (jobInfo != null) { var connectionString = RoleEnvironment.GetConfigurationSettingValue(AzureConstants.DiagnosticsConnectionStringName); CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); tableClient.CreateTableIfNotExist("jobs"); TableServiceContext serviceContext = tableClient.GetDataServiceContext(); JobLogEntity jobLogEntity = new JobLogEntity(jobInfo); serviceContext.AddObject("jobs", jobLogEntity); serviceContext.SaveChangesWithRetries(); } } catch (Exception ex) { Trace.TraceError("Error logging detail for job {0}. Cause: {1}", jobId, ex); } }