Exemple #1
0
 void ITimerService.Register(string id, TimeSpan due, TimeSpan period, Func <Task> callback)
 {
     timers.Add(id, registry.RegisterTimer(grain, async s =>
     {
         SetExecuting();
         await callback();
     },
                                           null, due, period));
 }
Exemple #2
0
 public Task ScheduleDelayedPing(IGenericPingSelf <T> target, T t, TimeSpan delay)
 {
     _timerRegistry.RegisterTimer(
         GrainContext,
         o =>
     {
         this.logger.LogDebug("***Timer fired for pinging {0}***", target.GetPrimaryKey());
         return(target.Ping(t));
     },
         null,
         delay,
         TimeSpan.FromMilliseconds(-1));
     return(Task.CompletedTask);
 }
        /// <inheritdoc/>
        public override Task Initialize(IStreamQueueMapper queueMapper)
        {
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }
            this.allQueues = new ReadOnlyCollection <QueueId>(queueMapper.GetAllQueues().ToList());
            if (this.allQueues.Count == 0)
            {
                return(Task.CompletedTask);
            }
            this.leaseProvider = this.serviceProvider.GetRequiredService(options.LeaseProviderType) as ILeaseProvider;
            NotifyAfterStart().Ignore();
            //make lease renew frequency to be every half of lease time, to avoid renew failing due to timing issues, race condition or clock difference.
            ITimerRegistry timerRegistry = this.serviceProvider.GetRequiredService <ITimerRegistry>();

            this.renewLeaseTimer = timerRegistry.RegisterTimer(null, this.MaintainAndBalanceQueues, null, this.options.SiloMaturityPeriod, this.options.LeaseLength.Divide(2));
            //try to acquire maximum leases every leaseLength
            this.tryAcquireMaximumLeaseTimer = timerRegistry.RegisterTimer(null, this.AcquireLeaseToMeetMaxResponsibility, null, this.options.SiloMaturityPeriod, this.options.SiloMaturityPeriod);
            //Selector default to round robin selector now, but we can make a further change to make selector configurable if needed.  Selector algorithm could
            //be affecting queue balancing stablization time in cluster initializing and auto-scaling
            this.queueSelector = new RoundRobinSelector <QueueId>(this.allQueues);
            return(MaintainAndBalanceQueues(null));
        }
 public override Task OnActivateAsync()
 {
     timerRegistry.RegisterTimer(this, TickExpirationPolicy, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
 }