コード例 #1
0
ファイル: Scheduler.cs プロジェクト: ichttt/Twice
        public Scheduler(string fileName, ITwitterContextList contextList, ITwitterConfiguration twitterConfig)
        {
            FileName = fileName;
            JobProcessors.Add(SchedulerJobType.DeleteStatus, new DeleteStatusProcessor(contextList));
            JobProcessors.Add(SchedulerJobType.CreateStatus, new CreateStatusProcessor(contextList, twitterConfig));

            if (File.Exists(FileName))
            {
                var json = File.ReadAllText(FileName);
                try
                {
                    Jobs.AddRange(JsonConvert.DeserializeObject <List <SchedulerJob> >(json));
                }
                catch (Exception ex)
                {
                    LogTo.WarnException("Failed to load joblist from file", ex);
                }
            }

            JobIdCounter = Jobs.Any()
                                ? Jobs.Max(j => j.JobId) + 1
                                : 0;

            SleepTime = 1000;
        }
コード例 #2
0
ファイル: Scheduler.cs プロジェクト: ichttt/Twice
 internal Scheduler(string fileName, ITwitterContextList contextList, ITwitterConfiguration twitterConfig,
                    IJobProcessor testProcessor, int sleepTime = 1000)
     : this(fileName, contextList, twitterConfig)
 {
     JobProcessors.Add(SchedulerJobType.Test, testProcessor);
     SleepTime = sleepTime;
 }
コード例 #3
0
ファイル: Scheduler.cs プロジェクト: ichttt/Twice
        internal bool ProcessJob(SchedulerJob job)
        {
            if (job.TargetTime <= DateTime.Now)
            {
                IJobProcessor processor;
                if (JobProcessors.TryGetValue(job.JobType, out processor))
                {
                    processor.Process(job);
                    return(true);
                }

                LogTo.Warn($"Unknown job type was scheduled ({job.JobType})");
            }

            return(false);
        }
コード例 #4
0
        public async Task ProcessJobs(object processBucket)
        {
            //CurrentLogWriter.Debug("Job assigner has started processing jobs.");
            try
            {
                AryaTask job;
                using (var aryaServicesDb = new AryaServicesDbDataContext())
                {
                    job =
                        aryaServicesDb.AryaTasks.FirstOrDefault(
                            s => s.Status.ToLower() == WorkerState.New.ToString().ToLower());

                    if (job == null)
                    {
                        return;
                    }
                    CurrentLogWriter.InfoFormat(
                        "Job ID: {0} Starting\tDescription:{1}\tSubmitted by:{2}\tSubmitted on:{3}\tJob type:{4}\tProcess bucket:{5}",
                        job.ID, job.Description, job.SubmittedBy, job.SubmittedOn, job.JobType, processBucket);
                    job.JobAssignedOn = DateTime.Now;
                    job.Status        = WorkerState.Working.ToString();

                    aryaServicesDb.SubmitChanges();
                }
                string currentJobStatus, emailAddresses = string.Empty;
                try
                {
                    if (JobProcessors.ContainsKey(job.JobType))
                    {
                        //create the job instance
                        var currentJobType = JobProcessors[job.JobType];

                        var jobExecutor =
                            (WorkerBase)
                            Activator.CreateInstance(currentJobType,
                                                     new object[]
                        {
                            Path.Combine(Settings.Default.ArgumentFileBasePath,
                                         job.ArgumentDirectoryPath)
                        });

                        jobExecutor.CurrentLogWriter    = CurrentLogWriter;
                        jobExecutor.WorkerStatusChange += AryaServices.UpdateWorkerStatusInDb;
                        emailAddresses = jobExecutor.Arguments.NotificationEmailAddresses;
                        ProcessEmailJobStatus(emailAddresses, job, true, "Started");
                        await Task.Run(() => jobExecutor.Run());

                        jobExecutor.SaveSummary();
                        currentJobStatus = jobExecutor.Summary.State.ToString();
                    }
                    else
                    {
                        currentJobStatus = WorkerState.Abort.ToString();
                        CurrentLogWriter.ErrorFormat("{0}: {1} not found in the dll provided", job.ID, job.JobType);
                    }
                }
                catch (Exception ex)
                {
                    var message = string.Empty;
                    var e       = ex;
                    while (e != null)
                    {
                        message = Environment.NewLine + e.Message;
                        e       = e.InnerException;
                    }
                    CurrentLogWriter.Error(ex.Source + message + Environment.NewLine + ex.StackTrace);
                    currentJobStatus = WorkerState.Abort.ToString();
                    CurrentLogWriter.Error(ex.SerializeObject());
                }

                using (var aryaServicesDb = new AryaServicesDbDataContext())
                {
                    job        = aryaServicesDb.AryaTasks.First(t => t.ID == job.ID);
                    job.Status = currentJobStatus;
                    ProcessEmailJobStatus(emailAddresses, job, true);
                    CurrentLogWriter.InfoFormat("Job Id: {0} Finished processing, Last Status: {1}", job.ID,
                                                currentJobStatus);
                    job.LastUpdateOn = DateTime.Now;
                    aryaServicesDb.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                CurrentLogWriter.Error(ex.SerializeObject());
            }

            CurrentLogWriter.Debug("Job assigner is exiting.");
        }