Exemple #1
0
 private static void ExecuteForcedFeeding([NotNull] EventFeed eventFeed, TimeSpan delayUpperBound)
 {
     try
     {
         lock (eventFeed)
             eventFeed.ExecuteForcedFeeding(delayUpperBound);
     }
     catch (Exception)
     {
         eventFeed.Shutdown();
         throw;
     }
 }
Exemple #2
0
 private void RunFeed([NotNull] EventFeed eventFeed, TimeSpan delayBetweenIterations, CancellationToken cancellationToken)
 {
     periodicJobRunner.RunPeriodicJobWithLeaderElection(FormatFeedJobName(eventFeed),
                                                        delayBetweenIterations,
                                                        jobAction: jobCancellationToken => ExecuteFeeding(eventFeed, jobCancellationToken),
                                                        onTakeTheLead: () =>
     {
         eventFeed.Initialize();
         return(eventFeed);
     },
                                                        onLoseTheLead: () =>
     {
         eventFeed.Shutdown();
         return(eventFeed);
     },
                                                        cancellationToken);
 }
Exemple #3
0
        private void RunFeeds([CanBeNull] string singleLeaderElectionKey, TimeSpan delayBetweenIterations, [NotNull, ItemNotNull] IBlade[] blades, CancellationToken cancellationToken)
        {
            if (!blades.Any())
            {
                throw new InvalidOperationException("No feeds to run");
            }

            if (string.IsNullOrEmpty(singleLeaderElectionKey))
            {
                foreach (var blade in blades)
                {
                    var eventFeed = new EventFeed(feedKey: blade.BladeId.BladeKey, new[] { blade });
                    RunFeed(eventFeed, delayBetweenIterations, cancellationToken);
                    runningFeeds.Add(eventFeed);
                }
            }
            else
            {
                var eventFeed = new EventFeed(feedKey: singleLeaderElectionKey, blades);
                RunFeed(eventFeed, delayBetweenIterations, cancellationToken);
                runningFeeds.Add(eventFeed);
            }
        }
Exemple #4
0
 private static void ExecuteFeeding([NotNull] EventFeed eventFeed, CancellationToken cancellationToken)
 {
     lock (eventFeed)
         eventFeed.ExecuteFeeding(cancellationToken);
 }
Exemple #5
0
 private static string FormatFeedJobName([NotNull] EventFeed eventFeed)
 {
     return($"{eventFeed.FeedKey}-PeriodicJob");
 }