Exemple #1
0
        private void Launch(IJobExecutionContext context, MiddlewareJob job)
        {
            var process = new Process();

            try
            {
                var startInfo = new ProcessStartInfo
                {
                    FileName        = job.JobExecutable,
                    UseShellExecute = false,
                    CreateNoWindow  = true,
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    Arguments       = "\"" + job.JobKey + "\""
                };

                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    throw new JobExecutionException(context.JobDetail.Description +
                                                    " returned with exit code " +
                                                    process.ExitCode);
                }

                job.LastRunStatus = JobRunStatus.Success;
            }
            catch (Exception exception)
            {
                _logger.Exception("Error launching or executing " + context.JobDetail.JobType.AssemblyQualifiedName, exception);
                throw new JobExecutionException(exception);
            }
        }
Exemple #2
0
        public void InsertJob(MiddlewareJob job)
        {
            const string insertMiddlewareJob = @"INSERT INTO [dbo].[Job]
                                                            ([JobKey]
                                                            ,[Schedule]
                                                            ,[JobExecutable]
                                                            ,[IsActive]
                                                            ,[LastRunExecutionTime]
                                                            ,[LastRunStatus]
                                                            ,[LastRunDateTime]
                                                            ,[NextRunDateTime]
                                                            ,[IsAlerted])
                                                            VALUES
                                                            (@JobKey
                                                            ,@Schedule
                                                            ,@JobExecutable
                                                            ,@IsActive
                                                            ,@LastRunExecutionTime
                                                            ,@LastRunStatus
                                                            ,@LastRunDateTime
                                                            ,@NextRunDateTime
                                                            ,@IsAlerted)";

            using (var connection = DatabaseConnectionFactory.GetWarehouseManagementConnection())
            {
                connection.Open();

                connection.Execute(insertMiddlewareJob, job);
            }
        }
        public ActionResult LaunchJob(MiddlewareJob job)
        {
            if (!_jobService.LaunchJob(job.JobKey, User.Identity.Name))
            {
                Response.StatusCode = (int)HttpStatusCode.ExpectationFailed;
            }

            return(GetIndex());
        }
        public ActionResult SaveJobSchedule(MiddlewareJob job)
        {
            if (!_jobService.SaveMiddlewareJobSchedule(job.JobKey, job.Schedule))
            {
                Response.StatusCode = (int)HttpStatusCode.ExpectationFailed;
            }

            return(GetIndex());
        }
        public void ScheduleJob(MiddlewareJob job, IScheduler scheduler)
        {
            var jobKey = new JobKey(job.JobKey);

            var trigger = CreateTrigger(job);

            var jobDetail = JobBuilder.
                            Create(typeof(ConsoleJob)).
                            WithIdentity(jobKey).
                            WithDescription("Scheduled " + job.JobKey + " to run on schedule " + job.Schedule).
                            StoreDurably(). // specifies job should stick around even if not scheduled (allows reschedule)
                            Build();

            scheduler.ScheduleJob(jobDetail, trigger);
            _logger.Info("Scheduled " + job.JobKey + " to run on schedule " + job.Schedule);
        }
        private ITrigger CreateTrigger(MiddlewareJob job)
        {
            ITrigger trigger;

            if (job.Schedule.Contains("M"))
            {
                int minutes = Convert.ToInt32(job.Schedule.Replace("M", string.Empty));

                trigger = TriggerBuilder
                          .Create()
                          .WithSimpleSchedule(s => s.WithIntervalInMinutes(minutes).RepeatForever())
                          .WithIdentity(new TriggerKey(job.JobKey))
                          .Build();
            }
            else if (job.Schedule.Contains("S"))
            {
                int seconds = Convert.ToInt32(job.Schedule.Replace("S", string.Empty));

                trigger = TriggerBuilder
                          .Create()
                          .WithSimpleSchedule(s => s.WithIntervalInSeconds(seconds).RepeatForever())
                          .WithIdentity(new TriggerKey(job.JobKey))
                          .Build();
            }
            else if (job.Schedule.Contains("H"))
            {
                int hours = Convert.ToInt32(job.Schedule.Replace("H", string.Empty));

                trigger = TriggerBuilder.Create()
                          .WithSimpleSchedule(s => s.WithIntervalInHours(hours).RepeatForever())
                          .WithIdentity(new TriggerKey(job.JobKey))
                          .Build();
            }
            else
            {
                trigger = TriggerBuilder.Create()
                          .WithCronSchedule(job.Schedule)
                          .WithIdentity(new TriggerKey(job.JobKey))
                          .StartNow()
                          .Build();
            }

            return(trigger);
        }
Exemple #7
0
        public void UpdateJob(MiddlewareJob job)
        {
            const string updateMiddlewareJob = @"UPDATE [Job]
                                                 SET Schedule = @Schedule,
                                                     JobExecutable = @JobExecutable,
	                                                 IsActive = @IsActive,
                                                     LastRunExecutionTime = @LastRunExecutionTime,
	                                                 JobKey = @JobKey,
                                                     LastRunStatus = @LastRunStatus,
                                                     LastRunDateTime = @LastRunDateTime,
                                                     NextRunDateTime = @NextRunDateTime,
                                                     JobType = @JobType,
                                                     IsAlerted = @IsAlerted
                                                 WHERE JobId = @JobId";

            using (var connection = DatabaseConnectionFactory.GetWarehouseManagementConnection())
            {
                connection.Open();

                connection.Execute(updateMiddlewareJob, job);
            }
        }
Exemple #8
0
        private bool RescheduleJob(MiddlewareJob job)
        {
            try
            {
                if (QuartzRemoteScheduler.Instance == null || !QuartzRemoteScheduler.Instance.IsStarted)
                {
                    return(false);
                }

                QuartzRemoteScheduler.Instance.UnscheduleJob(new TriggerKey(job.JobKey));
                QuartzRemoteScheduler.Instance.DeleteJob(new JobKey(job.JobKey));
                _log.Debug("Uncheduled job " + job.JobKey);

                _serverScheduler.ScheduleJob(job, QuartzRemoteScheduler.Instance);

                return(true);
            }
            catch (Exception exception)
            {
                _log.Exception("Failed to reschedule " + job.JobKey, exception);
                return(false);
            }
        }
 public ActionResult SaveJobActiveStatus(MiddlewareJob job)
 {
     _jobService.SaveMiddlewareJobActiveStatus(job.JobKey, job.IsActive);
     return(GetIndex());
 }