Exemple #1
0
        public static void ReSchedule(string guid)
        {
            var task = JobRepository.GetByGuid(guid);

            JobRepository.SetTaskOneTimeOnly(guid, task.Alias, task.Data);
            JobScheduler.LaunchJob <JobList.CommandJob>(guid);
        }
Exemple #2
0
        public static void LaunchJob <T>(string guid) where T : IJob
        {
            var task   = JobRepository.GetByGuid(guid);
            var dbtask = JobBuilder.Create <T>()
                         .WithIdentity(task.Alias, Guid.NewGuid().ToString())
                         .UsingJobData("data", task.Data)
                         .UsingJobData("jobID", task.Guid)
                         .Build();
            ITrigger trigger;

            switch (task.TriggerPeriod)
            {
            case TriggerPeriod.IsOneTimeOnly:
                trigger = DefineOneTimeOnlyTrigger(task.Alias, task.StartTime);
                break;

            case TriggerPeriod.IsCron:
                trigger = DefineCronTrigger(task.Alias, task.StartTime, task.CronExpression);
                break;

            case TriggerPeriod.WithInterval:
                trigger = DefineIntervalTrigger(task.Alias, task.StartTime, task.IntervalType, task.IntervalSpan, task.Count);
                break;

            case TriggerPeriod.Other:
                trigger = DefineDefaultTrigger(task.Alias);
                break;

            default:
                trigger = DefineDefaultTrigger(task.Alias);
                break;
            }
            Scheduler.ScheduleJob(dbtask, trigger);
        }
Exemple #3
0
        public static void Schedule(string jobName, string command)
        {
            var guid = Guid.NewGuid().ToString();

            JobRepository.SetTaskOneTimeOnly(guid, jobName, command);
            Thread.Sleep(20);
            JobScheduler.LaunchJob <JobList.CommandJob>(guid);
        }
Exemple #4
0
            public void Execute(IJobExecutionContext context)
            {
                //var key = context.JobDetail.Key;
                var dataMap = context.JobDetail.JobDataMap;
                var command = dataMap.GetString("data");
                var jobId   = dataMap.GetString("jobID");
                var cmd     = Terminal.Terminal.Execute(command);

                JobRepository.AddResult(jobId, cmd);
            }
Exemple #5
0
        public static void Schedule(string jobName, string command, string cron)
        {
            var guid = Guid.NewGuid().ToString();
            var data = new [] {
                command.GetFirstString(),
                command.GetAllStringsButFirst()
            };
            var dataJson = JsonConvert.SerializeObject(data);

            JobRepository.SetTaskCron(guid, jobName, dataJson, cron);
            Thread.Sleep(20);
            JobScheduler.LaunchJob <JobList.CommandJob>(guid);
        }
Exemple #6
0
 public static void Start(bool recoverTasks)
 {
     if (recoverTasks == false)
     {
         Scheduler.Start();
     }
     else
     {
         Scheduler.Start();
         var taskList = JobRepository.GetEnabled();
         ConsoleLogger.Log($"{taskList.ToArray().Length} job(s) scheduled");
         if (taskList.ToArray().Length <= 0)
         {
             return;
         }
         foreach (var task in taskList.Where(task => task != null))
         {
             LaunchJob <JobList.CommandJob>(task.Guid);
         }
     }
 }
Exemple #7
0
 public static void ScheduleWGuid(string guid, string command)
 {
     JobRepository.SetTaskOneTimeOnly(guid, command);
     Thread.Sleep(20);
     JobScheduler.LaunchJob <JobList.CommandJob>(guid);
 }