//--- Methods --- public Result Dispatch(UpdateRecord updateRecord, Result result) { _log.DebugFormat("moving update record '{0}' to dispatch queue ({1})", updateRecord.Id, _dispatchQueue.Count); if (!_dispatchQueue.TryEnqueue(new QueueItem(updateRecord, result))) { throw new InvalidOperationException(string.Format("Enqueue of '{0}' failed.", updateRecord.Id)); } return(result); }
/// <summary> /// Queue a document for indexing. /// </summary> /// <param name="id">Primary key of document.</param> /// <param name="revision">Revision of document.</param> /// <param name="doc">Document to be indexed.</param> public void QueueUpdate(int id, int revision, XDoc doc) { Map(doc); foreach (IndexInfo index in Indicies) { // TODO (arnec): what to do when enqueue fails... _processingQueue.TryEnqueue(new WorkItem(index, id, revision, doc)); } }
//--- Methods --- public void Dispatch(UpdateRecord updateRecord) { _log.DebugFormat("moving update record '{0}' from delay to dispatch queue", updateRecord.Id); Interlocked.Increment(ref _dispatchCount); if (!_dispatchQueue.TryEnqueue(updateRecord)) { Interlocked.Decrement(ref _dispatchCount); throw new InvalidOperationException(string.Format("Enqueue of '{0}' failed.", updateRecord.Id)); } }
internal IEnumerator <IYield> QueueUpdateTemplates(DreamContext context, DreamMessage request, Result <DreamMessage> response) { var doc = request.ToDocument(); var wikiId = doc["@wikiid"].AsText; var channel = doc["channel"].AsText; _log.DebugFormat("received event '{0}' from '{1}'", channel, wikiId); if (!_processingQueue.TryEnqueue(doc)) { throw new InvalidOperationException("Enqueue of update event failed."); } response.Return(DreamMessage.Ok()); yield break; }
private void Queue(DateTime eventTime, XUri channel, XUri resource, string[] origin, XDoc doc) { doc.Attr("wikiid", _wikiid).Attr("event-time", eventTime); var data = new ChangeData(); data.Channel = channel; data.Resource = resource == null ? null : resource.WithoutQuery().WithoutFragment(); data.Origin = origin; data.Doc = doc; if (!_changeQueue.TryEnqueue(data)) { _log.WarnFormat("unable to enqueue change data into processing queue"); } }
/// <summary> /// Dispatch an event against the registered subscriptions. /// </summary> /// <param name="ev">Dispatch event instance.</param> public void Dispatch(DispatcherEvent ev) { if (ev.HasVisited(_owner)) { // this event is in a dispatch loop, so we drop it if (_log.IsWarnEnabled) { _log.WarnFormat("event for channel '{0}' already visited the service, dropping", ev.Channel); if (_log.IsDebugEnabled) { _log.Debug(" event origin:"); foreach (XUri origin in ev.Origins) { _log.DebugFormat(" - {0}", origin); } _log.Debug(" event route:"); foreach (XUri via in ev.Via) { _log.DebugFormat(" - {0}", via); } } } throw new DreamBadRequestException("Dispatch loop detected: The event has already been dispatched by this service"); } if (_log.IsDebugEnabled) { _log.DebugFormat("Dispatcher '{0}' dispatching '{1}' on channel '{2}' with resource '{3}'", _owner, ev.Id, ev.Channel, ev.Resource); } DispatcherEvent dispatchEvent = ev.WithVia(_owner); if (!_dispatchQueue.TryEnqueue(dispatchEvent)) { throw new InvalidOperationException(string.Format("Enqueue of '{0}' failed.", dispatchEvent.Id)); } }
private void CheckExpire(TaskTimer timer) { // get the next scheduled item NotificationUpdateRecord data; lock (_pending) { if (_queue.Count == 0) { _queueTimer.Change(_delay, TaskEnv.Current); return; } Tuplet <DateTime, string> key = _queue.Peek(); if (key.Item1 > DateTime.UtcNow) { _queueTimer.Change(key.Item1, TaskEnv.Current); return; } data = _pending[key.Item2]; _queue.Dequeue(); _pending.Remove(key.Item2); } // stuff data into dispatch queue so our worker thread can pick it up and process all data synchronously if (!_dispatchQueue.TryEnqueue(data)) { throw new InvalidOperationException(string.Format("Enqueue for user '{0}' failed.", data.UserId)); } // check for optimal sleep interval lock (_pending) { if (_queue.Count == 0) { _queueTimer.Change(_delay, TaskEnv.Current); return; } Tuplet <DateTime, string> key = _queue.Peek(); _queueTimer.Change(key.Item1, TaskEnv.Current); } }