public override StateData GetStateData(string jobId) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } Task <ItemResponse <Documents.Job> > task = Storage.Container.ReadItemWithRetriesAsync <Documents.Job>(jobId, new PartitionKey((int)DocumentTypes.Job)); task.Wait(); if (task.Result.Resource != null) { Documents.Job job = task.Result; // get the state document Task <ItemResponse <State> > stateTask = Storage.Container.ReadItemWithRetriesAsync <State>(job.StateId, new PartitionKey((int)DocumentTypes.State)); stateTask.Wait(); if (stateTask.Result.Resource != null) { State state = stateTask.Result; return(new StateData { Name = state.Name, Reason = state.Reason, Data = state.Data }); } } return(null); }
public override StateData GetStateData(string jobId) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } Uri uri = UriFactory.CreateDocumentUri(Storage.Options.DatabaseName, Storage.Options.CollectionName, jobId); Task <DocumentResponse <Documents.Job> > task = Storage.Client.ReadDocumentWithRetriesAsync <Documents.Job>(uri); task.Wait(); if (task.Result.Document != null) { Documents.Job job = task.Result; // get the state document uri = UriFactory.CreateDocumentUri(Storage.Options.DatabaseName, Storage.Options.CollectionName, job.StateId); Task <DocumentResponse <State> > stateTask = Storage.Client.ReadDocumentWithRetriesAsync <State>(uri); stateTask.Wait(); if (stateTask.Result.Document != null) { State state = stateTask.Result; return(new StateData { Name = state.Name, Reason = state.Reason, Data = state.Data }); } } return(null); }
public override string GetJobParameter(string id, string name) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Task <ItemResponse <Documents.Job> > task = Storage.Container.ReadItemWithRetriesAsync <Documents.Job>(id, new PartitionKey((int)DocumentTypes.Job)); Documents.Job data = task.Result; return(data?.Parameters.Where(p => p.Name == name).Select(p => p.Value).FirstOrDefault()); }
public override string GetJobParameter(string id, string name) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Uri uri = UriFactory.CreateDocumentUri(Storage.Options.DatabaseName, Storage.Options.CollectionName, id); Task <DocumentResponse <Documents.Job> > task = Storage.Client.ReadDocumentAsync <Documents.Job>(uri); Documents.Job data = task.Result; return(data?.Parameters.Where(p => p.Name == name).Select(p => p.Value).FirstOrDefault()); }
public override JobData GetJobData(string jobId) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } Uri uri = UriFactory.CreateDocumentUri(Storage.Options.DatabaseName, Storage.Options.CollectionName, jobId); Task <DocumentResponse <Documents.Job> > task = Storage.Client.ReadDocumentWithRetriesAsync <Documents.Job>(uri, new RequestOptions { PartitionKey = new PartitionKey((int)DocumentTypes.Job) }); task.Wait(); if (task.Result.Document != null) { Documents.Job data = task.Result; InvocationData invocationData = data.InvocationData; invocationData.Arguments = data.Arguments; Common.Job job = null; JobLoadException loadException = null; try { job = invocationData.DeserializeJob(); } catch (JobLoadException ex) { loadException = ex; } return(new JobData { Job = job, State = data.StateName, CreatedAt = data.CreatedOn, LoadException = loadException }); } return(null); }
public override string CreateExpiredJob(Common.Job job, IDictionary <string, string> parameters, DateTime createdAt, TimeSpan expireIn) { if (job == null) { throw new ArgumentNullException(nameof(job)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } InvocationData invocationData = InvocationData.SerializeJob(job); Documents.Job entityJob = new Documents.Job { InvocationData = invocationData, Arguments = invocationData.Arguments, CreatedOn = createdAt, ExpireOn = createdAt.Add(expireIn), Parameters = parameters.Select(p => new Parameter { Name = p.Key, Value = p.Value }).ToArray() }; Task <ResourceResponse <Document> > task = Storage.Client.CreateDocumentWithRetriesAsync(Storage.CollectionUri, entityJob, new RequestOptions { PartitionKey = new PartitionKey((int)DocumentTypes.Job) }); task.Wait(); if (task.Result.StatusCode == HttpStatusCode.Created || task.Result.StatusCode == HttpStatusCode.OK) { return(entityJob.Id); } return(string.Empty); }
public override JobData GetJobData(string jobId) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } Task <ItemResponse <Documents.Job> > task = Storage.Container.ReadItemWithRetriesAsync <Documents.Job>(jobId, new PartitionKey((int)DocumentTypes.Job)); task.Wait(); if (task.Result.Resource != null) { Documents.Job data = task.Result; InvocationData invocationData = data.InvocationData; invocationData.Arguments = data.Arguments; Common.Job job = null; JobLoadException loadException = null; try { job = invocationData.DeserializeJob(); } catch (JobLoadException ex) { loadException = ex; } return(new JobData { Job = job, State = data.StateName, CreatedAt = data.CreatedOn, LoadException = loadException }); } return(null); }
public override JobData GetJobData(string jobId) { if (jobId == null) { throw new ArgumentNullException(nameof(jobId)); } Uri uri = UriFactory.CreateDocumentUri(Storage.Options.DatabaseName, Storage.Options.CollectionName, jobId); Task <DocumentResponse <Documents.Job> > task = Storage.Client.ReadDocumentAsync <Documents.Job>(uri); Documents.Job data = task.Result; if (data != null) { InvocationData invocationData = data.InvocationData; invocationData.Arguments = data.Arguments; Common.Job job = null; JobLoadException loadException = null; try { job = invocationData.Deserialize(); } catch (JobLoadException ex) { loadException = ex; } return(new JobData { Job = job, State = data.StateName, CreatedAt = data.CreatedOn, LoadException = loadException }); } return(null); }