Example #1
0
        private async Task <Response> TakeAsync(ITransferQueue <JObject> selectedQ, Request request, CancellationToken ct = default)
        {
            if (selectedQ == null)
            {
                return(FormatResponse(request.Payload, status: (int)HttpStatusCode.BadRequest));
            }

            JObject payload = await selectedQ.TakeAsync(timeout : Convert.ToInt32(request.Headers["timeout"]), cToken : ct);

            bool failure = payload == null;

            if (failure)
            {
                payload = request.Payload;
            }
            return(FormatResponse(payload, failure ? (int)HttpStatusCode.RequestTimeout : (int)HttpStatusCode.OK));
        }
Example #2
0
        private async void CheckLogs()
        {
            try
            {
                do
                {
                    string report = await queue.TakeAsync(MAX_WAIT_TIME, cToken);

                    if (report == null)
                    {
                        continue;
                    }
                    writes.Add(SequentialCopyAsync(report));
                } while (!cToken.IsCancellationRequested);
            } catch (OperationCanceledException)
            {
                ////server shutting down
            }
            Task.WaitAll(writes.ToArray());
        }