示例#1
0
        public bool ExecuteJob(string jobId)
        {
            var job = Provider.Database.Read <Job>("Id = {0}", jobId);

            if (job == null)
            {
                throw new APIException("Job not found: " + jobId);
            }
            try
            {
                var worker = BaseWorker.GetWorker(job.Command);
                if (worker == null)
                {
                    throw new APIException("Worker not defined for " + job.Command);
                }

                worker.ExecuteInternal(job);
            }
            catch (Exception ex)
            {
                job.State = JobStates.TryAgain;
                job.Save();

                JobData jd = Provider.Database.Read <JobData>("JobId={0}", job.Id);
                if (jd == null)
                {
                    jd = new JobData()
                    {
                        JobId = job.Id
                    }
                }
                ;
                jd.Request  = jd.Request ?? "";
                jd.Response = ex.Message;
                jd.Save();
            }

            return(true);
        }