コード例 #1
0
        public PeriodicJobWithLeaderElection(
            [NotNull] IRemoteLockCreator remoteLockCreator,
            [NotNull] IPeriodicTaskRunner periodicTaskRunner,
            [NotNull] IGraphiteClient graphiteClient,
            [NotNull] ILog logger,
            [NotNull] string jobName,
            TimeSpan delayBetweenIterations,
            TimeSpan leaderAcquisitionAttemptDelay,
            [NotNull] Action <CancellationToken> jobAction,
            [CanBeNull] Action onTakeTheLead,
            [CanBeNull] Action onLoseTheLead,
            CancellationToken cancellationToken)
        {
            this.remoteLockCreator             = remoteLockCreator;
            this.periodicTaskRunner            = periodicTaskRunner;
            this.graphiteClient                = graphiteClient;
            this.logger                        = logger;
            this.jobName                       = jobName;
            this.delayBetweenIterations        = delayBetweenIterations;
            this.leaderAcquisitionAttemptDelay = leaderAcquisitionAttemptDelay;
            this.jobAction                     = jobAction;
            this.onTakeTheLead                 = onTakeTheLead;
            this.onLoseTheLead                 = onLoseTheLead;
            isDisposed = false;
            jobCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);

            leaderActivityReportingJobId        = $"leaderActivityReportingJobId-{jobName}";
            leaderActivityReportingGraphitePath = $"SubSystem.LeaderElection.{jobName}.{Dns.GetHostName()}";

            jobThread = new Thread(() => ThreadProc(jobCancellationTokenSource.Token))
            {
                Name         = jobName,
                IsBackground = true,
            };
            jobThread.Start();
            this.logger.Info("Job thread has started for {JobName}", new { JobName = jobName });
        }
コード例 #2
0
 public static void Register([NotNull] this IPeriodicTaskRunner periodicTaskRunner, [NotNull] string taskId, TimeSpan period, [NotNull] Action taskAction)
 {
     periodicTaskRunner.Register(new ActionPeriodicTask(taskId, taskAction), period);
 }
コード例 #3
0
 public static void Unregister([NotNull] this IPeriodicTaskRunner periodicTaskRunner, [NotNull] string taskId, TimeSpan timeout)
 {
     periodicTaskRunner.Unregister(taskId, (int)timeout.TotalMilliseconds);
 }
コード例 #4
0
 public TestRtqPeriodicJobRunner(IPeriodicTaskRunner periodicTaskRunner, Lazy <IPeriodicJobRunnerWithLeaderElection> lazyJobRunnerWithLeaderElection)
 {
     this.periodicTaskRunner = periodicTaskRunner;
     this.lazyJobRunnerWithLeaderElection = lazyJobRunnerWithLeaderElection;
 }
 public PeriodicJobRunnerWithLeaderElection(IRemoteLockCreator remoteLockCreator, IPeriodicTaskRunner periodicTaskRunner, IGraphiteClient graphiteClient, ILog logger)
 {
     this.remoteLockCreator  = remoteLockCreator;
     this.periodicTaskRunner = periodicTaskRunner;
     this.graphiteClient     = graphiteClient;
     this.logger             = logger.ForContext(nameof(PeriodicJobRunnerWithLeaderElection));
 }