コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Schedule"/> class.
 /// The schedule is disabled until the initialise function is called.
 /// </summary>
 public Schedule()
 {
     mShouldExecute         = false;
     Statistics             = new MessagingStatistics();
     Statistics.ComponentId = Id;
     mTimerConfig           = new ScheduleTimerConfig(enforceSetting: false);
 }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: rajeshcr/Microservice
        /// <summary>
        /// Sets the timer configuration from a ScheduleTimerConfig object.
        /// </summary>
        /// <param name="timerConfig">The timer configuration.</param>
        public void TimerSet(ScheduleTimerConfig timerConfig)
        {
            if (timerConfig == null)
            {
                throw new ArgumentNullException("timerConfig");
            }

            Frequency   = timerConfig.Interval;
            InitialTime = timerConfig.InitialWaitUTCTime;
            InitialWait = timerConfig.InitialWait;
        }
コード例 #3
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="execute">The execution function.</param>
 /// <param name="timerConfig">The timer poll configuration.</param>
 /// <param name="context">The optional schedule context</param>
 /// <param name="name">The name of the schedule.</param>
 /// <param name="isLongRunning">A boolean flag that specifies whether the process is long running.</param>
 /// <param name="tearUp">The set up action.</param>
 /// <param name="tearDown">The clear down action.</param>
 /// <param name="isMasterJob">Indicates whether this schedule is associated to a master job.</param>
 public CommandJobSchedule(Func <Schedule, CancellationToken, Task> execute
                           , ScheduleTimerConfig timerConfig
                           , object context             = null
                           , string name                = null
                           , bool isLongRunning         = false
                           , Action <Schedule> tearUp   = null
                           , Action <Schedule> tearDown = null
                           , bool isMasterJob           = false
                           ) : base(execute, timerConfig, name, context, isLongRunning)
 {
     Initialise(execute, timerConfig, context, name, isLongRunning, tearUp, tearDown, isMasterJob);
 }
コード例 #4
0
        /// <summary>
        /// This is the constructor for registering a manual schedule.
        /// </summary>
        /// <param name="command">The command to process.</param>
        /// <param name="config">The time configuration.</param>
        /// <param name="referenceId">The optional reference id for tracking.</param>
        /// <param name="isLongRunning">Specifies whether this is a long running process.</param>
        /// <param name="policy">The command policy.</param>
        public CommandScheduleInline(Func <CommandScheduleInlineContext, Task> command
                                     , ScheduleTimerConfig config = null
                                     , string referenceId         = null
                                     , bool isLongRunning         = false
                                     , CommandPolicy policy       = null) : base(policy)
        {
            mCommand = command ?? throw new ArgumentNullException("command", "The command function cannot be null");

            mTimerConfig   = config ?? new ScheduleTimerConfig(enforceSetting: false);
            mReferenceId   = referenceId;
            mIsLongRunning = isLongRunning;
        }
コード例 #5
0
        /// <summary>
        /// Creates and registers a schedule.
        /// </summary>
        /// <param name="execute">The execution function.</param>
        /// <param name="timerConfig">The timer poll configuration. If this is set to null, the schedule will fire immediately after it is registered.</param>
        /// <param name="context">The optional schedule context</param>
        /// <param name="name">The name of the schedule.</param>
        /// <param name="isLongRunning">A boolean flag that specifies whether the process is long running.</param>
        /// <param name="tearUp">The set up action.</param>
        /// <param name="tearDown">The clear down action.</param>
        /// <returns>Returns the new master job schedule.</returns>
        protected virtual CommandJobSchedule MasterJobScheduleRegister(Func <Schedule, CancellationToken, Task> execute
                                                                       , ScheduleTimerConfig timerConfig = null
                                                                       , object context             = null
                                                                       , string name                = null
                                                                       , bool isLongRunning         = false
                                                                       , Action <Schedule> tearUp   = null
                                                                       , Action <Schedule> tearDown = null)
        {
            var schedule = new CommandJobSchedule();

            schedule.Initialise(execute, timerConfig, context, name, isLongRunning, tearUp, tearDown, true);

            return(JobScheduleRegister(schedule));
        }
コード例 #6
0
        /// <summary>
        /// Initialises the schedule.
        /// </summary>
        /// <param name="execute">The execution function.</param>
        /// <param name="timerConfig">The timer poll configuration.</param>
        /// <param name="context">The optional schedule context</param>
        /// <param name="name">The name of the schedule.</param>
        /// <param name="isLongRunning">A boolean flag that specifies whether the process is long running.</param>
        /// <param name="tearUp">The set up action.</param>
        /// <param name="tearDown">The clear down action.</param>
        /// <param name="isMasterJob">Indicates whether this schedule is associated to a master job.</param>
        public virtual void Initialise(Func <Schedule, CancellationToken, Task> execute
                                       , ScheduleTimerConfig timerConfig
                                       , object context             = null
                                       , string name                = null
                                       , bool isLongRunning         = false
                                       , Action <Schedule> tearUp   = null
                                       , Action <Schedule> tearDown = null
                                       , bool isMasterJob           = false)
        {
            base.Initialise(execute, timerConfig, name, context, isLongRunning);

            TearUp      = tearUp;
            TearDown    = tearDown;
            IsMasterJob = isMasterJob;
        }
コード例 #7
0
        /// <summary>
        /// This extension adds the in-line command to the pipeline
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="function">The command schedule function.</param>
        /// <param name="timerConfig">The schedule timer configuration.</param>
        /// <param name="referenceId">The optional command reference id</param>
        /// <param name="isLongRunning">Specifies whether the schedule will be long running.</param>
        /// <param name="startupPriority">The command start-up priority.</param>
        /// <param name="channelIncoming">The incoming channel. This is optional if you pass channel information in the header.</param>
        /// <returns>Returns the pipeline.</returns>
        public static P AddSchedule <P>(this P pipeline
                                        , Func <CommandScheduleInlineContext, Task> function
                                        , ScheduleTimerConfig timerConfig = null
                                        , string referenceId  = null
                                        , bool isLongRunning  = false
                                        , int startupPriority = 100
                                        , IPipelineChannelIncoming <P> channelIncoming = null
                                        )
            where P : IPipeline
        {
            var command = new CommandScheduleInline(function, timerConfig, referenceId, isLongRunning);

            pipeline.AddCommand(command, startupPriority, null, channelIncoming);

            return(pipeline);
        }
コード例 #8
0
ファイル: Schedule.cs プロジェクト: rajeshcr/Microservice
        /// <summary>
        /// Initialises the schedule.
        /// </summary>
        /// <param name="execute">The execute.</param>
        /// <param name="name">The name.</param>
        /// <param name="context">The context.</param>
        /// <param name="timerConfig">The optional timer configuration.</param>
        /// <param name="isLongRunning">Specifies whether the schedule is a long running process.</param>
        public virtual void Initialise(Func <Schedule, CancellationToken, Task> execute, string name = null, object context = null, ScheduleTimerConfig timerConfig = null, bool isLongRunning = false)
        {
            mExecute = execute ?? throw new ArgumentNullException("execute", $"{GetType().Name}/{nameof(Initialise)}");

            mShouldExecute = true;

            Name    = name;
            Context = context;

            mTimerConfig = timerConfig;
            if (timerConfig != null)
            {
                TimerSet(timerConfig);
            }

            IsLongRunning = isLongRunning;
        }
コード例 #9
0
        /// <summary>
        /// This method registers a schedule.
        /// </summary>
        /// <param name="action">The schedule action.</param>
        /// <param name="frequency">The poll frequency.</param>
        /// <param name="name">The optional poll name.</param>
        /// <param name="initialWait">The optional initial wait until the poll begins.</param>
        /// <param name="initialTime">The optional initial time to start the poll.</param>
        /// <param name="shouldExecute">A flag that indicates whether the poll is active. The default is true.</param>
        /// <param name="isInternal">Specifies whether the poll is internal. The default is false.</param>
        /// <returns>Returns the new schedule after it has been added to the collection.</returns>
        public Schedule Register(Func <Schedule, CancellationToken, Task> action
                                 , TimeSpan?frequency
                                 , string name          = null
                                 , TimeSpan?initialWait = null
                                 , DateTime?initialTime = null
                                 , bool shouldExecute   = true
                                 , bool isInternal      = false
                                 )
        {
            var timer = new ScheduleTimerConfig(frequency, initialWait, initialTime, shouldExecute);

            var schedule = new Schedule(action, timer, name)
            {
                ShouldExecute = shouldExecute,
                IsInternal    = isInternal
            };

            return(Register(schedule));
        }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MasterJobNegotiationStrategy"/> class.
 /// </summary>
 public MasterJobNegotiationStrategyDebug() : base("Debug")
 {
     InitialPoll = new ScheduleTimerConfig(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100));
 }
コード例 #11
0
 /// <summary>
 /// This is the default constructor.
 /// </summary>
 /// <param name="execute">The function to execute.</param>
 /// <param name="timerConfig">The timer configuration.</param>
 /// <param name="name">The name.</param>
 public CommandTimeoutSchedule(Func <Schedule, CancellationToken, Task> execute, ScheduleTimerConfig timerConfig, string name)
     : base(execute, timerConfig, name)
 {
 }
コード例 #12
0
ファイル: Schedule.cs プロジェクト: rajeshcr/Microservice
 /// <summary>
 /// Initializes a new instance of the <see cref="Schedule"/> class.
 /// </summary>
 /// <param name="execute">The async schedule function.</param>
 /// <param name="name">The schedule name.</param>
 /// <param name="context">The context.</param>
 /// <param name="timerConfig">The optional timer configuration.</param>
 /// <param name="isLongRunning">Specifies whether the schedule is a long running process.</param>
 public Schedule(Func <Schedule, CancellationToken, Task> execute, string name = null, object context = null, ScheduleTimerConfig timerConfig = null, bool isLongRunning = false) : this()
 {
     Initialise(execute, name, context);
     Statistics.Name = name;
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MasterJobNegotiationPollSchedule"/> class.
 /// </summary>
 /// <param name="execute">The async schedule function.</param>
 /// <param name="timerConfig">The timer poll configuration.</param>
 /// <param name="name">The masterjob name.</param>
 public MasterJobNegotiationPollSchedule(Func <Schedule, CancellationToken, Task> execute, ScheduleTimerConfig timerConfig, string name = null)
     : base(execute, timerConfig, name, isLongRunning: false)
 {
 }