protected void UpdateExecutionInfo(Action <ScheduledJobExecution> updateAction)
        {
            try
            {
                if (JobExecutionId == Guid.Empty)
                {
                    return;
                }

                using (var unitOfWork = UnitOfWorkManager.Begin())
                {
                    var jobExecution = JobExecutionRepository.Get(JobExecutionId);
                    updateAction.Invoke(jobExecution);
                    JobExecutionRepository.Update(jobExecution);

                    // save changes
                    unitOfWork.Complete();
                }
            }
            catch (Exception e)
            {
                // rollback
                Logger.Error(e.Message, e);
            }
        }
        /// <summary>
        /// Create execution record
        /// </summary>
        public async Task <Guid> CreateExecutionRecordAsync(Guid executionId, Action <ScheduledJobExecution> prepare)
        {
            try
            {
                if (executionId == Guid.Empty)
                {
                    throw new Exception($"{nameof(executionId)} must not be empty");
                }

                using (var unitOfWork = UnitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
                {
                    var existingExecution = await JobExecutionRepository.GetAll().FirstOrDefaultAsync(ex => ex.Id == executionId);

                    ScheduledJobExecution jobExecution = null;

                    if (existingExecution != null && existingExecution.Status == ExecutionStatus.Enqueued)
                    {
                        jobExecution        = existingExecution;
                        jobExecution.Status = ExecutionStatus.InProgress;
                    }
                    else
                    {
                        var job = await JobRepository.GetAsync(Id);

                        var trigger = GetTrigger();
                        jobExecution = new ScheduledJobExecution()
                        {
                            Id = existingExecution != null
                                ? Guid.NewGuid()
                                : executionId,
                            Job             = job,
                            StartedOn       = DateTime.Now,
                            Status          = ExecutionStatus.Enqueued,
                            Trigger         = trigger,
                            ParentExecution = existingExecution
                        };
                    }

                    prepare?.Invoke(jobExecution);

                    await JobExecutionRepository.InsertAsync(jobExecution);

                    await unitOfWork.CompleteAsync();

                    return(jobExecution.Id);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                throw;
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            const string path = @"d:\\tick-tock";

            BlobRepository blobs = BlobRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "blobs");
            });

            JobExecutionRepository executions = JobExecutionRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "executions");
            });

            JobRepository jobs = JobRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "jobs");
            });

            JobTaskRepository tasks = JobTaskRepositoryFactory.Create(with =>
            {
                with.Blobs      = blobs;
                with.Executions = executions;
            });

            JobRunner runner = JobRunnerFactory.Create(with =>
            {
                with.Executions = executions;
                with.Jobs       = jobs;
                with.Tasks      = tasks;
            });

            Bootstrapper bootstrapper = new Bootstrapper(path);
            Uri          uri          = new Uri("http://localhost:1234");

            using (var host = new NancyHost(bootstrapper, uri))
            {
                host.Start();

                while (true)
                {
                    runner.Run();
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                }
            }
        }
Exemple #4
0
        public JobsModule(JobRepository jobs, JobExecutionRepository executions)
            : base("/api/jobs")
        {
            this.jobs       = jobs;
            this.executions = executions;

            Get["/"]         = parameters => HandleGetAllJobs();
            Post["/"]        = parameters => HandlePostJob(this.Bind <DynamicDictionary>());
            Get["/{job}"]    = parameters => HandleGetJob(parameters.job);
            Patch["/{job}"]  = parameters => HttpStatusCode.OK;
            Delete["/{job}"] = parameters => HttpStatusCode.OK;

            Get["/{job}/versions"]              = parameters => HttpStatusCode.OK;
            Get["/{job}/versions/{version}"]    = parameters => HttpStatusCode.OK;
            Delete["/{job}/versions/{version}"] = parameters => HttpStatusCode.OK;

            Get["/{job}/schedule"]   = parameters => HttpStatusCode.OK;
            Patch["/{job}/schedule"] = parameters => HttpStatusCode.OK;

            Get["/{job}/executions"]             = parameters => HttpStatusCode.OK;
            Get["/{job}/executions/newest"]      = parameters => HttpStatusCode.OK;
            Get["/{job}/executions/{execution}"] = parameters => HttpStatusCode.OK;
        }
 protected ScheduledJobExecution GetExecutionRecord()
 {
     return(JobExecutionRepository.Get(JobExecutionId));
 }