Ejemplo n.º 1
0
        protected bool DetermineCurrentlyRunning(ContextControllerCondition startCondition)
        {
            // we are not currently running if either of the endpoints is not crontab-triggered
            var contextDetailInitiatedTerminated = _factory.ContextDetailInitiatedTerminated;

            if ((contextDetailInitiatedTerminated.Start is ContextDetailConditionCrontab) &&
                ((contextDetailInitiatedTerminated.End is ContextDetailConditionCrontab)))
            {
                var scheduleStart = ((ContextDetailConditionCrontab)contextDetailInitiatedTerminated.Start).Schedule;
                var scheduleEnd   = ((ContextDetailConditionCrontab)contextDetailInitiatedTerminated.End).Schedule;

                var engineImportService    = _factory.StatementContext.EngineImportService;
                var nextScheduledStartTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleStart, _factory.TimeProvider.Time, engineImportService.TimeZone,
                    engineImportService.TimeAbacus);
                long nextScheduledEndTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleEnd, _factory.TimeProvider.Time, engineImportService.TimeZone,
                    engineImportService.TimeAbacus);

                return(nextScheduledStartTime >= nextScheduledEndTime);
            }

            if (startCondition is ContextControllerConditionTimePeriod)
            {
                var condition = (ContextControllerConditionTimePeriod)startCondition;
                var endTime   = condition.ExpectedEndTime;
                if (endTime != null && endTime <= 0)
                {
                    return(true);
                }
            }

            return(startCondition is ContextControllerConditionImmediate);
        }
Ejemplo n.º 2
0
        public bool UpdateOutputCondition(int newEventsCount, int oldEventsCount)
        {
            if ((ExecutionPathDebugLog.IsEnabled) && (Log.IsDebugEnabled))
            {
                Log.Debug(".updateOutputCondition, " +
                          "  newEventsCount==" + newEventsCount +
                          "  oldEventsCount==" + oldEventsCount);
            }

            bool output      = false;
            long currentTime = _agentInstanceContext.StatementContext.SchedulingService.Time;

            if (_state.CurrentReferencePoint == null)
            {
                _state.CurrentReferencePoint = currentTime;
                _state.NextScheduledTime     = ScheduleComputeHelper.ComputeNextOccurance(_state.ScheduleSpec, currentTime, _agentInstanceContext.StatementContext.MethodResolutionService.EngineImportService.TimeZone);
                output = true;
            }

            if (_state.NextScheduledTime <= currentTime)
            {
                _state.NextScheduledTime = ScheduleComputeHelper.ComputeNextOccurance(_state.ScheduleSpec, currentTime, _agentInstanceContext.StatementContext.MethodResolutionService.EngineImportService.TimeZone);
                output = true;
            }

            return(output);
        }
Ejemplo n.º 3
0
 public long? GetExpectedEndTime(
     ContextManagerRealization realization,
     ScheduleSpec scheduleSpec)
 {
     var classpathImportService = realization.AgentInstanceContextCreate.ImportServiceRuntime;
     return ScheduleComputeHelper.ComputeNextOccurance(
         scheduleSpec,
         realization.AgentInstanceContextCreate.TimeProvider.Time,
         classpathImportService.TimeZone,
         classpathImportService.TimeAbacus);
 }
 public static long ComputeScheduleMinimumNextOccurance(ScheduleSpec[] schedules, long time, ImportServiceRuntime classpathImportService) {
     var value = Int64.MaxValue;
     foreach (var spec in schedules) {
         var computed = ScheduleComputeHelper.ComputeNextOccurance(
             spec,
             time,
             classpathImportService.TimeZone,
             classpathImportService.TimeAbacus);
         if (computed < value) {
             value = computed;
         }
     }
     return value;
 }
Ejemplo n.º 5
0
        public static bool DetermineCurrentlyRunning(
            ContextControllerCondition startCondition,
            ContextControllerInitTerm controller)
        {
            if (startCondition.IsImmediate) {
                return true;
            }

            var factory = controller.InitTermFactory;
            var spec = factory.InitTermSpec;
            if (spec.IsOverlapping) {
                return false;
            }

            // we are not currently running if either of the endpoints is not crontab-triggered
            if (spec.StartCondition is ContextConditionDescriptorCrontab &&
                spec.EndCondition is ContextConditionDescriptorCrontab) {
                var scheduleStart = ((ContextControllerConditionCrontab) startCondition).Schedule;

                var endCron = (ContextConditionDescriptorCrontab) spec.EndCondition;
                var scheduleEnd = ScheduleExpressionUtil.CrontabScheduleBuild(
                    endCron.Evaluators,
                    controller.Realization.AgentInstanceContextCreate);

                var importService = controller.Realization.AgentInstanceContextCreate.ImportServiceRuntime;
                var time = controller.Realization.AgentInstanceContextCreate.SchedulingService.Time;
                var nextScheduledStartTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleStart,
                    time,
                    importService.TimeZone,
                    importService.TimeAbacus);
                var nextScheduledEndTime = ScheduleComputeHelper.ComputeNextOccurance(
                    scheduleEnd,
                    time,
                    importService.TimeZone,
                    importService.TimeAbacus);
                return nextScheduledStartTime >= nextScheduledEndTime;
            }

            if (startCondition.Descriptor is ContextConditionDescriptorTimePeriod) {
                var descriptor = (ContextConditionDescriptorTimePeriod) startCondition.Descriptor;
                var endTime = descriptor.GetExpectedEndTime(controller.Realization);
                if (endTime != null && endTime <= 0) {
                    return true;
                }
            }

            return startCondition is ContextConditionDescriptorImmediate;
        }
Ejemplo n.º 6
0
        public void TestAddTwice()
        {
            service.Add(100, callbacks[0], slots[0][0]);
            Assert.IsTrue(service.IsScheduled(callbacks[0]));
            service.Add(100, callbacks[0], slots[0][0]);

            service.Add(
                ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE),
                callbacks[1],
                slots[0][0]);
            service.Add(
                ScheduleComputeHelper.ComputeNextOccurance(new ScheduleSpec(), service.Time, TimeZoneInfo.Utc, TimeAbacusMilliseconds.INSTANCE),
                callbacks[1],
                slots[0][0]);
        }