Ejemplo n.º 1
0
        public void AddSchedule(ScheduleEntry schedule)
        {
            if (!CronExpression.IsValidExpression(schedule.CronSchedule))
            {
                _statsPlugin.IncrementState("schedules:invalidcron");
                throw new InvalidConfigurationException("Cron expression is invalid");
            }

            lock (_lock)
            {
                schedule.Created = DateTime.Now;
                ExecuteSchedule(schedule);
                _schedules.Add(schedule);
                _statsPlugin.IncrementState("schedules:added");
            }

            Save();
        }
Ejemplo n.º 2
0
        private ResponseMessage CreateSchedule(IncomingMessage message, string command, string cronSchedule)
        {
            var schedule = new ScheduleEntry
            {
                Guid = Guid.NewGuid(),
                Channel = message.Channel,
                ChannelType = message.ChannelType,
                Command = command,
                CronSchedule = cronSchedule,
                UserId = message.UserId,
                UserName = message.Username,
                Created = DateTime.Now
            };

            if (!CronExpression.IsValidExpression(cronSchedule))
            {
                return message.ReplyToChannel($"Unknown cron schedule `'{cronSchedule}'`");
            }

            if (string.IsNullOrEmpty(schedule.Command))
            {
                return message.ReplyToChannel("Please enter a command to be scheduled.");
            }

            _schedulePlugin.AddSchedule(schedule);
            return message.ReplyToChannel($"Schedule created for command '{schedule.Command}'.");
        }
Ejemplo n.º 3
0
        private void ExecuteSchedule(ScheduleEntry schedule)
        {
            IJobDetail job = JobBuilder.Create<ScheduledJob>()
                            .UsingJobData("guid", schedule.Guid.ToString())
                            .WithIdentity(schedule.Guid.ToString())
                            .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(new TriggerKey(schedule.Guid.ToString(), "job"))
                .WithCronSchedule(schedule.CronSchedule)
                .Build();

            _scheduler.ScheduleJob(job, trigger);
        }