/// <summary>
        /// @see IJobOperator#Start .
        /// </summary>
        /// <param name="jobName"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        /// <exception cref="NoSuchJobException">&nbsp;</exception>
        /// <exception cref="JobInstanceAlreadyExistsException">&nbsp;</exception>
        /// <exception cref="JobParametersInvalidException">&nbsp;</exception>
        public long?Start(string jobName, string parameters)
        {
            _logger.Info("Checking status of job with name= {0}", jobName);
            JobParameters jobParameters = _jobParametersConverter.GetJobParameters(PropertiesConverter.StringToProperties(parameters));

            if (JobRepository.IsJobInstanceExists(jobName, jobParameters))
            {
                throw new JobInstanceAlreadyExistsException(string.Format("Cannot start a job instance that already exists with name={0} and parameters={1}", jobName, parameters));
            }

            IJob job = JobRegistry.GetJob(jobName);

            _logger.Info("Attempting to launch job with name={0} and parameters={1}", jobName, parameters);

            try
            {
                return(JobLauncher.Run(job, jobParameters).Id);
            }
            catch (JobExecutionAlreadyRunningException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job execution already running", jobName, parameters), e);
            }
            catch (JobRestartException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job not restartable", jobName, parameters), e);
            }
            catch (JobInstanceAlreadyCompleteException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job already complete", jobName, parameters), e);
            }
        }
示例#2
0
        /// <summary>
        /// Execute the job provided by delegating to the <see cref="IJobLauncher"/>to
        /// prevent duplicate executions. The job parameters will be generated by the
        /// <see cref="IJobParametersExtractor"/>provided (if any), otherwise empty. On a
        /// restart, the job parameters will be the same as the last (failed) execution.
        /// </summary>
        /// <param name="stepExecution"></param>
        protected override void DoExecute(StepExecution stepExecution)
        {
            ExecutionContext executionContext = stepExecution.ExecutionContext;

            executionContext.Put(StepConstants.StepTypeKey, GetType().Name);
            JobParameters jobParameters;

            if (executionContext.ContainsKey(JobParametersKey))
            {
                jobParameters = (JobParameters)executionContext.Get(JobParametersKey);
            }
            else
            {
                jobParameters = _jobParametersExtractor.GetJobParameters(Job, stepExecution);
                executionContext.Put(JobParametersKey, jobParameters);
            }

            JobExecution jobExecution = JobLauncher.Run(Job, jobParameters);

            if (jobExecution.Status.IsUnsuccessful())
            {
                // AbstractStep will take care of the step execution status
                throw new UnexpectedJobExecutionException("Step failure: the delegate Job failed in JobStep.");
            }
        }
示例#3
0
        public RssService(string serviceName, string baseAddress, JobLauncher jobLauncher)
        {
            _baseAddress = baseAddress;
            ServiceName  = serviceName;

            _jobLauncher = jobLauncher;
        }
示例#4
0
        /// <summary>
        /// Handle any additional receiving the node might want to do
        /// in the receiver class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void HandleAdditionalReceiving(object sender, DataReceivedEventArgs e)
        {
            NodeComm receivedData = e as NodeComm;

            if (receivedData != null)
            {
                switch (receivedData.Protocol)
                {
                case NodeComm.MessageType.File:
                    // This will block on the IOStream until the file reading
                    // is over. The next thing sent over the network must be a file.
                    _job = JsonConvert.DeserializeObject <JobRef>(receivedData.Args[1]);
                    FileRead.ReadInWriteOut(Proxy.IOStream, _job.FileName);
                    //job = receivedData;
                    // after we have finished reading the data, let node manager know
                    OnDataReceived(new NodeComm(DataReceivedEventArgs.ConstructMessage("fileread")));
                    break;

                case NodeComm.MessageType.Execute:
                    //TODO, this should be its own task/thread
                    _parent.Logger.Log("Node: executing");
                    JobLauncher j = new JobLauncher(_job, _parent);
                    j.LaunchJob();
                    break;

                case NodeComm.MessageType.Shutdown:
                case NodeComm.MessageType.Quit:
                    // shutting down or quitting, we are done receving
                    DoneReceiving = true;
                    break;
                }
            }
        }
 void Application_Start(object sender, EventArgs e)
 {
     // Code that runs on application startup
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     JobLauncher.StartUp();
 }
示例#6
0
 public TaskManager(
     TaskRepository taskRepository,
     TaskPool taskPool,
     JobLauncher jobLauncher,
     IConfigurationProvider configuration)
 {
     _taskRepository = taskRepository;
     _taskPool       = taskPool;
     _jobLauncher    = jobLauncher;
     _configuration  = configuration;
 }
示例#7
0
        public TaskService(
            string serviceName,
            DbChangesListener dbChangesListener,
            JobLauncher jobLauncher,
            TaskManager taskManager)
        {
            _dbChangesListener = dbChangesListener;
            _jobLauncher       = jobLauncher;
            _taskManager       = taskManager;

            ServiceName = serviceName;
        }
        /// <summary>
        /// @see IJobOperator#StartNextInstance .
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        /// <exception cref="NoSuchJobException">&nbsp;</exception>
        /// <exception cref="JobParametersNotFoundException">&nbsp;</exception>
        /// <exception cref="UnexpectedJobExecutionException">&nbsp;</exception>
        /// <exception cref="JobParametersInvalidException">&nbsp;</exception>
        public long?StartNextInstance(string jobName)
        {
            _logger.Info("Locating parameters for next instance of job with name={0}", jobName);

            IJob job = JobRegistry.GetJob(jobName);
            IList <JobInstance> lastInstances = JobExplorer.GetJobInstances(jobName, 0, 1);

            IJobParametersIncrementer incrementer = job.JobParametersIncrementer;

            if (incrementer == null)
            {
                throw new JobParametersNotFoundException(
                          string.Format("No job parameters incrementer found for job={0}", jobName));
            }

            JobParameters parameters;

            if (!lastInstances.Any())
            {
                parameters = incrementer.GetNext(new JobParameters());
                if (parameters == null)
                {
                    throw new JobParametersNotFoundException(
                              string.Format("No bootstrap parameters found for job={0}", jobName));
                }
            }
            else
            {
                IList <JobExecution> lastExecutions = JobExplorer.GetJobExecutions(lastInstances.First());
                parameters = incrementer.GetNext(lastExecutions.First().JobParameters);
            }

            _logger.Info("Attempting to launch job with name={0} and parameters={1}", jobName, parameters);
            try
            {
                return(JobLauncher.Run(job, parameters).Id);
            }
            catch (JobExecutionAlreadyRunningException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job already running", jobName, parameters), e);
            }
            catch (JobRestartException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job not restartable", jobName, parameters), e);
            }
            catch (JobInstanceAlreadyCompleteException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job instance already complete", jobName, parameters), e);
            }
        }
        /// <summary>
        /// @see IJobOperator#Restart .
        /// </summary>
        /// <param name="executionId"></param>
        /// <returns></returns>
        /// <exception cref="JobInstanceAlreadyCompleteException">&nbsp;</exception>
        /// <exception cref="NoSuchJobExecutionException">&nbsp;</exception>
        /// <exception cref="NoSuchJobException">&nbsp;</exception>
        /// <exception cref="JobRestartException">&nbsp;</exception>
        /// <exception cref="JobParametersInvalidException">&nbsp;</exception>
        public long?Restart(long executionId)
        {
            _logger.Info("Checking status of job execution with id= {0}", executionId);

            JobExecution jobExecution = FindExecutionById(executionId);

            string        jobName    = jobExecution.JobInstance.JobName;
            IJob          job        = JobRegistry.GetJob(jobName);
            JobParameters parameters = jobExecution.JobParameters;

            _logger.Info("Attempting to resume job with name={0} and parameters={1}", jobName, parameters);
            try
            {
                return(JobLauncher.Run(job, parameters).Id);
            }
            catch (JobExecutionAlreadyRunningException e)
            {
                throw new UnexpectedJobExecutionException(string.Format(IllegalStateMsg, "job execution already running", jobName, parameters), e);
            }
        }
示例#10
0
 static void Main(string[] args)
 {
     //System.Diagnostics.Debugger.Launch();
     JobLauncher.StartUp();
     Console.WriteLine("程式已啟動...");
     //Application.Run();
     while (true)
     {
         Console.WriteLine("請輸入=>r:立即執行; q:結束");
         var cmd = Console.ReadLine();
         if (cmd == "r")
         {
             JobScheduler.LaunchImmediately();
         }
         else if (cmd == "q")
         {
             break;
         }
         //Thread.Yield();
     }
 }
示例#11
0
 public void TestSetup()
 {
     launcher = new JobLauncher();
     state    = new SchedulerState(Task.CompletedTask, CancellationToken.None);
     job      = Substitute.For <IStreamJob>();
 }