public void Error(AppOperation op, Exception ex)
 {
     if (op.State != OperationState.Running)
     {
         return;
     }
     lock (operations)
     {
         operations.Remove(op);
     }
     op.Stop(true);
     currentOperation.Value = null;
     op.Exception           = ex;
     Interlocked.Increment(ref failedOperations);
     //add the op to the error operation list
     lock (errorOperations)
     {
         errorOperations.AddLast(op);
         if (errorOperations.Count > MaxErrorOperations)
         {
             errorOperations.RemoveFirst();
         }
     }
     //record to database
     statsService.LogFailedTask(op, ErrorReason.Exception);
 }
Esempio n. 2
0
        public void LogFailedTask(AppOperation op, ErrorReason reason)
        {
            if (statsServer == null)
            {
                return;
            }
            if (op.DbLogged)
            {
                return;
            }
            op.DbLogged = true;
            var fullUrl = $"{statsServer}/stats/aspose3d/error";
            var form    = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "sessionId", op.SessionId },
                { "app", ((int)op.App).ToString() },
                { "duration", ((long)op.Duration.TotalMilliseconds).ToString() },
                { "reason", ((int)reason).ToString() }
            });

            try
            {
                var task = httpClient.PostAsync(fullUrl, form);
                Task.WaitAll(new Task[] { task }, timeout);
            }
            catch (Exception e)
            {
                logger.LogError("Failed to forward failed task to stats server", e);
            }
        }
 public void Done(AppOperation op)
 {
     if (op.State != OperationState.Running)
     {
         return;
     }
     lock (operations)
     {
         operations.Remove(op);
     }
     op.Stop(false);
     currentOperation.Value = null;
     Interlocked.Increment(ref successedOperations);
     //record long operations
     lock (prolongOperations)
     {
         var to = new TimedOperation(op);
         if (prolongOperations.Count > 0 && to.Duration <= prolongOperations[0].Duration)
         {
             return;
         }
         int i = prolongOperations.BinarySearch(to);
         if (i < 0)
         {
             i = ~i;
             if (i == prolongOperations.Count)
             {
                 prolongOperations.Add(to);
             }
             else
             {
                 prolongOperations.Insert(i, to);
             }
         }
         else
         {
             prolongOperations.Insert(i, to);
         }
         if (prolongOperations.Count > MaxProlongOperations)
         {
             prolongOperations.RemoveAt(0);
         }
     }
 }