コード例 #1
0
 //--- Constructors ---
 public NotificationDelayQueue(TimeSpan delay, CoroutineHandler<NotificationUpdateRecord, Result> callback) {
     _delay = delay;
     _callback = callback;
     _queueTimer = new TaskTimer(CheckExpire, null);
     _queueTimer.Change(_delay, TaskEnv.None);
     _dispatchQueue = new ProcessingQueue<NotificationUpdateRecord>(Dispatch, 10);
 }
コード例 #2
0
        private void Poll(TaskTimer timer) {
            if(!_poll) {
                timer.Change(TimeSpan.FromSeconds(1), TaskEnv.Current);
                return;
            }
            _poll = false;
            while(true) {

                // pull item from queue to store in out accumulation queue and hold on to it
                var item = _persistentQueue.Dequeue(TimeSpan.MaxValue);
                if(item == null) {

                    // didn't find an item, drop out of loop and set timer to check again later
                    timer.Change(TimeSpan.FromSeconds(1), TaskEnv.Current);
                    return;
                }
                var doc = item.Value;
                var wikiid = doc["@wikiid"].AsText;
                var id = new XUri("http://" + wikiid + "/" + doc["path"].AsText);
                lock(_data) {
                    UpdateRecord data;
                    XUri channel = doc["channel"].AsUri;
                    string action = channel.Segments[2];
                    if(!_data.TryGetValue(id, out data)) {
                        _log.DebugFormat("queueing '{0}' for '{1}'", action, id);
                        _queue.Enqueue(new Tuplet<DateTime, XUri>(DateTime.UtcNow.Add(_delay), id));
                        data = new UpdateRecord(id, doc, wikiid);
                    } else {
                        _log.DebugFormat("appending existing queue record '{0}' for '{1}'", action, id);
                        data = data.With(doc);
                    }
                    if(action != "create" && action != "move") {
                        data.ActionStack.PushDelete();
                    }
                    if(action != "delete") {
                        data.ActionStack.PushAdd();
                    }
                    data.QueueIds.Add(item.Id);
                    _data[id] = data;
                }
            }
        }
コード例 #3
0
ファイル: SqsPollClient.cs プロジェクト: heran/DReAM
 //--- Constructors ---
 public Listener(string queuename, Action<AwsSqsMessage> callback, IAwsSqsClient client, TaskTimerFactory timerFactory, TimeSpan interval)
 {
     _queuename = queuename;
     _callback = callback;
     _client = client;
     _cache = new ExpiringHashSet<string>(timerFactory);
     _cacheTimer = ((interval.TotalSeconds * 2 < 60) ? 60 : interval.TotalSeconds * 2 + 1).Seconds();
     _pollTimer = timerFactory.New(tt => Coroutine.Invoke(PollSqs, new Result()).WhenDone(r => _pollTimer.Change(interval, TaskEnv.None)), null);
     _pollTimer.Change(0.Seconds(), TaskEnv.None);
 }
コード例 #4
0
ファイル: TaskTimerFactory.cs プロジェクト: maximmass/DReAM
 /// <summary>
 /// Create a new timer and set its fire time.
 /// </summary>
 /// <param name="when">Relateive time from now until when the timer should fire.</param>
 /// <param name="handler">The action to invoke when the timer fires.</param>
 /// <param name="state">A state object to associate with the timer.</param>
 /// <param name="env">The environment in which the timer should fire.</param>
 /// <returns>New timer instance.</returns>
 public TaskTimer New(TimeSpan when, Action<TaskTimer> handler, object state, TaskEnv env)
 {
     var result = new TaskTimer(this, handler, state);
     result.Change(when, env);
     return result;
 }
コード例 #5
0
 //--- Constructors ---
 public UpdateDelayQueue(TimeSpan delay, IUpdateRecordDispatcher dispatcher) {
     _delay = delay;
     _dispatcher = dispatcher;
     _queueTimer = new TaskTimer(CheckExpire, null);
     _queueTimer.Change(_delay, TaskEnv.None);
 }
コード例 #6
0
ファイル: SearchInstanceData.cs プロジェクト: heran/DekiWiki
 private void Commit(TaskTimer tt) {
     if(_hasUncommittedData) {
         _disposalLock.ExecuteWithReadLock(() => {
             EnsureInstanceNotDisposed();
             lock(_updateSyncroot) {
                 _writer.Commit();
                 _searcherIsStale = true;
                 _hasUncommittedData = false;
             }
         });
     }
     tt.Change(_commitInterval, TaskEnv.None);
 }