IEventSlot IEventScheduler.FireOnce(TimeSpan delay, Action action) { Validate.NotNull(action); var now = DateTime.UtcNow; var info = new EventInfo { NextShot = now + delay, Count = 1, Action = action }; var slot = register_event(info); return slot; }
IEventSlot IEventScheduler.Idle(Action action) { Validate.NotNull(action); var info = new EventInfo { RepeatAfter = 1.Milliseconds(), Count = int.MaxValue, Action = action }; var slot = register_event(info); return slot; }
private void schedule_next_shot(EventInfo info) { DateTime now = DateTime.UtcNow; info.NextShot = now + info.RepeatAfter; }
private IEventSlot register_event(EventInfo info) { var slot = EventSlot.New(this); _repo.Add(info); _hasNewTriger.Set(); return slot; }
private bool remove_if_done(EventInfo info) { if (info.Count > 0) return false; _repo.Remove(info); return true; }
IEventSlot IEventScheduler.Schedule(EventInfo info, Action action) { Validate.NotNull(action); info.Action = action; var slot = register_event(info); return slot; }
private void invoke_event(EventInfo info) { try { info.Action(); info.Invoked++; } catch (Exception ex) { info.Failed++; info.LastFailure = ex; _log.Error(ex); } info.Count--; }
IEventSlot IEventScheduler.Repeat(TimeSpan period, Action action) { Validate.NotNull(action); Validate.That(period > TimeSpan.Zero, "Repeat with zero interval is not allowed"); var now = DateTime.UtcNow; var info = new EventInfo { NextShot = now + period, RepeatAfter = period, Count = int.MaxValue, Action = action }; var slot = register_event(info); return slot; }
void ISchedulerRepo.Remove(EventInfo info) { _events.Remove(info); }
void ISchedulerRepo.Add(EventInfo info) { _events.AddLast(info); }
void ISchedulerRepo.Remove(EventInfo info) { lock(_mutex) _impl.Remove(info); }
void ISchedulerRepo.Add(EventInfo info) { lock(_mutex) _impl.Add(info); }