public void ExecuteJob(Job job, CancellationToken token) { if (job is null) { return; } try { _executor.Execute(job, token); _logger?.Verbose($"Job has executed: {job}."); ArchiveJob(job); } catch (Exception exception) { job.Attempt.IncErrors(); if (job.Attempt.IsOver()) { throw new JobExecutionException("Attempts to complete the task have ended.", exception); } throw new JobAttemptException($"Attempt {job.Attempt.ErrorsNumber} for job {job}.", exception); } }
/// <inheritdoc /> public void Insert(Job job) { if (job is null) { throw new ArgumentNullException(nameof(job)); } try { using (var db = new LiteDatabase(_connectionString)) { var fullName = job.GetType().FullName; if (fullName == null) { return; } var collection = db.GetCollection(fullName.Replace(".", "_")); collection.Insert(BsonMapper.Global.ToDocument(job)); } _logger?.Verbose($"Job has inserted to repository: {job}"); } catch (Exception exception) { _logger?.Error(exception); throw; } }
/// <inheritdoc /> public void Insert(Job job) { using (var cn = new SQLiteConnection(ConnectionString)) { cn.Open(); var j = new JobRecord(job); cn.Insert(j); } _logger?.Verbose($"Job has inserted to repository: {job}"); }
private static void ReadRepositoryProcess(CancellationToken token) { while (true) { try { var jobs = _repository.Get(); DistributeOnQueues(jobs); ClearRepository(jobs); _logger?.Verbose("Read jobs from the repository."); Task.Delay(_options.PollingPeriod, token).Wait(token); } catch (OperationCanceledException) { _logger?.Information("Scheduler read repository process has stopped."); break; } catch (Exception exception) { _logger?.Error(exception); } } }