public override string CreateExpiredJob( [NotNull] Job job, [NotNull] IDictionary <string, string> parameters, DateTime createdAt, TimeSpan expireIn) { if (job == null) { throw new ArgumentNullException(nameof(job)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } var backgroundJob = new BackgroundJobEntry { Key = Guid.NewGuid().ToString(), // TODO: Change with Long type InvocationData = _options.DisableJobSerialization == false?InvocationData.SerializeJob(job) : null, Job = _options.DisableJobSerialization ? new Job(job.Type, job.Method, job.Args.ToArray()) : null, Parameters = new ConcurrentDictionary <string, string>(parameters, StringComparer.Ordinal), // TODO: case sensitivity CreatedAt = createdAt }; // TODO: Precondition: jobId does not exist _dispatcher.QueryAndWait(state => { // TODO: We need somehow to ensure that this entry isn't removed before initialization backgroundJob.ExpireAt = state.TimeResolver().Add(expireIn); state.JobCreate(backgroundJob); }); return(backgroundJob.Key); }
public bool TryGetJobData([NotNull] string jobId, out BackgroundJobEntry entry) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } return(_state.Jobs.TryGetValue(jobId, out entry)); }
public void JobCreate(BackgroundJobEntry job) { if (!_jobs.TryAdd(job.Key, job)) { // TODO: Panic } _jobIndex.Add(job); }
public void JobDelete(BackgroundJobEntry entry) { if (entry.ExpireAt.HasValue) { _jobIndex.Remove(entry); } _jobs.TryRemove(entry.Key, out _); if (entry.State?.Name != null && _jobStateIndex.TryGetValue(entry.State.Name, out var stateIndex)) { stateIndex.Remove(entry); if (stateIndex.Count == 0) { _jobStateIndex.Remove(entry.State.Name); } } }
public override string CreateExpiredJob(Job job, IDictionary <string, string> parameters, DateTime createdAt, TimeSpan expireIn) { var backgroundJob = new BackgroundJobEntry { Key = Guid.NewGuid().ToString(), // TODO: Change with Long type InvocationData = InvocationData.SerializeJob(job), Parameters = new ConcurrentDictionary <string, string>(parameters, StringComparer.Ordinal), CreatedAt = createdAt }; // TODO: Precondition: jobId does not exist _dispatcher.QueryAndWait(state => { backgroundJob.ExpireAt = state.TimeResolver().Add(expireIn); state.JobCreate(backgroundJob); }); return(backgroundJob.Key); }
public void JobSetState(BackgroundJobEntry job, StateEntry state) { if (job.State != null && _jobStateIndex.TryGetValue(job.State.Name, out var indexEntry)) { indexEntry.Remove(job); if (indexEntry.Count == 0) { _jobStateIndex.Remove(job.State.Name); } } job.State = state; if (!_jobStateIndex.TryGetValue(state.Name, out indexEntry)) { _jobStateIndex.Add(state.Name, indexEntry = new SortedSet <BackgroundJobEntry>(new BackgroundJobStateCreatedAtComparer())); } indexEntry.Add(job); }
public void JobExpire(BackgroundJobEntry job, TimeSpan?expireIn) { EntryExpire(job, _jobIndex, expireIn); }