Exemplo n.º 1
0
        /// <summary>
        /// Inserts or updates/replaces a specified job instance
        /// </summary>
        public async Task <JobInstance> SaveAsync(JobInstance jobInstance)
        {
            var insertOperation = TableOperation.InsertOrReplace(jobInstance);
            var result          = await JobInstancesTable.ExecuteAsync(insertOperation);

            return(result.Result as JobInstance);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deletes the specified job instance
        /// </summary>
        /// <param name="job"></param>
        /// <returns>Indicates whether the operation was successful</returns>
        public bool Delete(JobInstance jobInstance)
        {
            var deleteOperation = TableOperation.Delete(jobInstance);
            var result          = JobInstancesTable.Execute(deleteOperation);

            return(result.HttpStatusCode >= 200 && result.HttpStatusCode < 300);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Inserts or updates/replaces a specified job instances
        /// </summary>
        public JobInstance Save(JobInstance jobInstance)
        {
            var insertOperation = TableOperation.InsertOrReplace(jobInstance);
            //TODO research performance and operation impact of insert vs. merge
            //var mergeOperation = TableOperation.InsertOrMerge(job);
            var result = JobInstancesTable.Execute(insertOperation);

            return(result.Result as JobInstance);
        }
Exemplo n.º 4
0
        private JobInstanceDetail FinalStart(string message, Guid?instanceId = null)
        {
            Instance = new JobInstance(Job.Id, instanceId.GetValueOrDefault(Guid.NewGuid()), Job.Version);

            var detail = new JobInstanceDetail(Instance.JobId, Instance.InstanceId)
            {
                Date    = DateTime.UtcNow,
                Type    = JobDetailType.Started,
                Details = message
            };

            Instance.TotalDetails = 1;
            Instance.LastOn       = detail.Date;
            Instance.LastType     = detail.Type;
            Instance.StartedOn    = Instance.LastOn;

            Job.LastInstanceStatusOn = detail.Date;
            Job.LastInstanceStatus   = detail.Type.ToString();
            Job.TotalInstances++;
            Job.LastInstanceId = Instance.InstanceId;
            Job.IsRunning      = true;

            return(detail);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Deletes the specified job instance
        /// </summary>
        /// <param name="job"></param>
        /// <returns>Indicates whether the operation was successful</returns>
        public async Task <bool> DeleteAsync(JobInstance jobInstance)
        {
            var deleteOperation = TableOperation.Delete(jobInstance);
            var result          = await JobInstancesTable.ExecuteAsync(deleteOperation);

            var history = await GetJobInstanceAsync(jobInstance.JobId, jobInstance.StartedOn, jobInstance.InstanceId);

            if (history != null)
            {
                deleteOperation = TableOperation.Delete(history);
                _ = await JobInstancesTable.ExecuteAsync(deleteOperation);
            }

            var succeeded = result.HttpStatusCode >= 200 && result.HttpStatusCode < 300;

            if (succeeded)
            {
                //TODO if we got here, but this fails then we have orphan records in the details table.
                //TODO return more than a simple boolean and/or create a cleanup method that can run on a schedule for such events
                JobServiceHelper.DeleteAllEntitiesInBatches(JobInstanceDetailsTable, jobInstance.PartitionKey);
            }

            return(succeeded);
        }