Exemple #1
0
        public bool Handle(IMiramarTaskProvider taskProvider, IMiramarScheduleProvider scheduleProvider, IMiramarContextProvider contextProvider, IIstaMessage message)
        {
            var request = JsonMessageSerializer.DeserializeType(message.Body, new
            {
                requestId   = 0,
                requestedBy = string.Empty,
                requestedOn = DateTime.Now,
            });

            if (request == null)
            {
                return(false);
            }

            scheduleProvider.PublishSchedules();
            return(true);
        }
Exemple #2
0
        public void ThreadRun(CancellationToken token)
        {
            if (taskProvider == null)
            {
                taskProvider = MiramarConfigurationParser.ParseConfiguration("miramar.config");
            }

            if (scheduleProvider == null)
            {
                scheduleProvider = MiramarSchedulingParser.ParseSchedule("miramar.config");
            }

            if (contextProvider == null)
            {
                contextProvider = new MiramarContextProvider();
            }

            taskProvider.PublishConfiguration();
            scheduleProvider.PublishSchedules();

            using (var manual = new ManualResetEventSlim())
            {
                while (true)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    publisher.PublishHeartbeat(DateTime.Now);

                    var identifiers = scheduleProvider.IdentifyTasksToExecute(DateTime.Now);
                    logger.TraceFormat("Identified {0} tasks that should be ran.", identifiers.Length);

                    foreach (var identifier in identifiers)
                    {
                        logger.TraceFormat("Identified \"{0}\" should be ran.", identifier);

                        ActiveTaskContext context;
                        if (contextProvider.TryGetValue(identifier, out context) && context.IsRunning)
                        {
                            logger.WarnFormat("Task \"{0}\" has been scheduled to run but is currently active.",
                                              identifier);

                            logger.InfoFormat("Task \"{0}\" has been active since {1:yyyy-MM-dd hh:mm:ss}.",
                                              context.TaskName, context.StartDate);

                            continue;
                        }

                        ExecuteTask(identifier, token);
                    }

                    try
                    {
                        manual.Wait(TimeSpan.FromSeconds(15), token);
                    }
                    catch (OperationCanceledException)
                    {
                        break;
                    }
                }
            }

            var runningTasks = contextProvider
                               .GetRunningContexts()
                               .Select(x => x.RunningTask)
                               .ToArray();

            if (contextProvider.Any())
            {
                WaitOnTasks(runningTasks);
            }
        }