public async Task InvokeAsync(ScheduledTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken) { while (true) { var synchronizedTime = GetNextTriggerTime(triggerInfo, DateTimeOffset.UtcNow); if (synchronizedTime == null) { return; } var nextTriggerTime = synchronizedTime.Value; if (!triggerInfo.SynchronizeTimeZone) { //ignore offset nextTriggerTime = new DateTimeOffset(nextTriggerTime.DateTime, DateTimeOffset.UtcNow.Offset); } context.ReportNextTrigger(nextTriggerTime); await Task.Delay(nextTriggerTime - DateTimeOffset.UtcNow, cancellationToken); //important: use synchronized time var session = await context.CreateSession(SessionKey.Create("ScheduledTrigger", synchronizedTime.Value)); await session.Invoke(); } }
public async Task InvokeAsync(OnAppStartupTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken) { var session = await context.CreateSession(SessionKey.Create("OnAppStartup", DateTimeOffset.UtcNow)); await session.Invoke(); await Task.Delay(int.MaxValue, cancellationToken); }
public async Task InvokeAsync(SystemRestartTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken) { var now = DateTime.UtcNow; var uptime = TimeSpan.FromMilliseconds(GetTickCount64()); var startupTime = now.Add(-uptime); var session = await context.CreateSession(SessionKey.Create("SystemRestart")); if (!session.Info.Executions.Any(x => x.CreatedOn > startupTime)) { await session.Invoke(); } await Task.Delay(TimeSpan.MaxValue, cancellationToken); }
public async Task InvokeAsync(OnAppStartupTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken) { var session = await context.CreateSession(SessionKey.Create("OnAppStart", DateTime.Now.Date)); if (triggerInfo.OncePerDay) { if (session.Info.Executions.Any()) { await Task.Delay(int.MaxValue, cancellationToken); } } await session.Invoke(); await Task.Delay(int.MaxValue, cancellationToken); }
public OnJoinTriggerService(IClientEventNotifier clientEvents) { _clientEvents = clientEvents; _clientConnectedLock = new AsyncLock(); _sessionTrigger = new AsyncLazy <TaskSessionTrigger>(() => _context.CreateSession(SessionKey.Create("OnClientJoin"))); }
public async Task InvokeAsync(ImmediatelyTriggerInfo triggerInfo, TriggerContext context, CancellationToken cancellationToken) { var session = await context.CreateSession(SessionKey.Create("Immediate", DateTimeOffset.UtcNow)); await session.Invoke(); }