示例#1
0
 private void put(TodoQueue queue, TodoFrame todo, object transaction = null, bool leak = false)
 {
     try
     {
         m_QueueStore.Put(queue, todo, transaction);
         if (InstrumentationEnabled)
         {
             m_stat_PutTodoCount.IncrementLong(ALL);
             m_stat_PutTodoCount.IncrementLong(queue.Name);
         }
     }
     catch (Exception e)
     {
         var from = "put('{0}')".Args(queue.Name);
         Log(MessageType.Critical, from, "{0} Leaked: {1}".Args(todo, e.ToMessageWithType()), e);
         if (InstrumentationEnabled)
         {
             m_stat_QueueOperationErrorCount.IncrementLong(ALL);
             m_stat_QueueOperationErrorCount.IncrementLong(from);
         }
         if (leak)
         {
             throw;
         }
     }
 }
示例#2
0
                                          private bool checkDups(TodoQueue queue, TodoFrame todo)
                                          {
                                              var mode = queue.DuplicationHandling;

                                              if (mode == TodoQueue.DuplicationHandlingMode.NotDetected)
                                              {
                                                  return(false);          //never a duplicate
                                              }
                                              var result = checkDupsInMemory(todo);

                                              if (result || mode == TodoQueue.DuplicationHandlingMode.HostFastDetection)
                                              {
                                                  return(result);
                                              }

                                              result = checkDupsInQueueStore(queue, todo);

                                              if (result || mode == TodoQueue.DuplicationHandlingMode.HostAccurateDetection)
                                              {
                                                  return(result);
                                              }

                                              result = checkDupsInHostset(queue, todo);

                                              return(result);
                                          }
示例#3
0
        private TodoFrame toFrame(TodoQueue queue, BSONDocument doc)
        {
            try
            {
                var result = new TodoFrame();

                result.ID   = RowConverter.GDID_BSONtoCLR(doc[Query._ID] as BSONBinaryElement);
                result.Type = Guid.Parse(((BSONStringElement)doc[FLD_TODO_TYPE]).Value);
                result.CreateTimestampUTC = ((BSONDateTimeElement)doc[FLD_TODO_CREATETIMESTAMP]).Value;

                result.ShardingKey = elmStr(doc[FLD_TODO_SHARDINGKEY]);
                result.ParallelKey = elmStr(doc[FLD_TODO_PARALLELKEY]);

                result.Priority  = ((BSONInt32Element)doc[FLD_TODO_PRIORITY]).Value;
                result.StartDate = ((BSONDateTimeElement)doc[FLD_TODO_STARTDATE]).Value;

                result.CorrelationKey = elmStr(doc[FLD_TODO_CORRELATIONKEY]);

                result.State = ((BSONInt32Element)doc[FLD_TODO_STATE]).Value;
                result.Tries = ((BSONInt32Element)doc[FLD_TODO_TRIES]).Value;

                result.Serializer = ((BSONInt32Element)doc[FLD_TODO_SERIALIZER]).Value;
                result.Content    = elmBin(doc[FLD_TODO_CONTENT]);

                return(result);
            }
            catch (Exception error)
            {
                throw new MongoWorkersException(StringConsts.TODO_QUEUE_BSON_READ_ERROR.Args(queue, error.ToMessageWithType()), error);
            }
        }
示例#4
0
        public override void Complete(TodoQueue queue, TodoFrame todo, Exception error = null, object transaction = null)
        {
            if (DisposeStarted || queue == null || !todo.Assigned)
            {
                return;
            }

            //this provider ignores exceptions passed in error var
            m_Database[queue.Name].DeleteOne(Query.ID_EQ_GDID(todo.ID));
        }
示例#5
0
        public override void Put(TodoQueue queue, TodoFrame todo, object transaction)
        {
            if (DisposeStarted || queue == null || !todo.Assigned)
            {
                return;
            }
            var tName = queue.Name;
            var doc   = toBSON(queue, todo);

            m_Database[tName].Insert(doc);
        }
示例#6
0
        public override void Update(TodoQueue queue, Todo todo, bool sysOnly, object transaction)
        {
            if (DisposeStarted || queue == null || todo == null)
            {
                return;
            }

            var frame = new TodoFrame(todo, sysOnly ? (int?)null : TodoFrame.SERIALIZER_BSON);
            var doc   = toBSONUpdate(queue, frame, sysOnly);

            m_Database[queue.Name].Update(new UpdateEntry(Query.ID_EQ_GDID(todo.SysID), doc, false, false));
        }
示例#7
0
                                          private void complete(TodoQueue queue, TodoFrame todo, Exception error, object transaction = null)
                                          {
                                              try
                                              {
                                                  m_QueueStore.Complete(queue, todo, error, transaction);

                                                  if (error != null)
                                                  {
                                                      Log(MessageType.Error, "complete('{0}')".Args(queue.Name), "Completed with error: " + error.ToMessageWithType(), error);
                                                  }

                                                  if (InstrumentationEnabled)
                                                  {
                                                      m_stat_CompletedTodoCount.IncrementLong(ALL);
                                                      m_stat_CompletedTodoCount.IncrementLong(queue.Name);

                                                      if (error != null)
                                                      {
                                                          m_stat_CompletedErrorTodoCount.IncrementLong(ALL);
                                                          m_stat_CompletedErrorTodoCount.IncrementLong(queue.Name);
                                                      }
                                                      else
                                                      {
                                                          m_stat_CompletedOkTodoCount.IncrementLong(ALL);
                                                          m_stat_CompletedOkTodoCount.IncrementLong(queue.Name);
                                                      }
                                                  }
                                              }
                                              catch (Exception e)
                                              {
                                                  var from = "complete('{0}')".Args(queue.Name);
                                                  Log(MessageType.Critical, from, "{0} Leaked: {1}".Args(todo, e.ToMessageWithType()), e);
                                                  if (InstrumentationEnabled)
                                                  {
                                                      m_stat_QueueOperationErrorCount.IncrementLong(ALL);
                                                      m_stat_QueueOperationErrorCount.IncrementLong(from);
                                                  }
                                              }
                                          }
示例#8
0
        private BSONDocument toBSON(TodoQueue queue, TodoFrame todo)
        {
            var result = new BSONDocument();
            var t      = todo.GetType();

            result.Set(RowConverter.GDID_CLRtoBSON(Query._ID, todo.ID));

            result.Set(new BSONStringElement(FLD_TODO_TYPE, todo.Type.ToString()));
            result.Set(new BSONDateTimeElement(FLD_TODO_CREATETIMESTAMP, todo.CreateTimestampUTC));

            result.Set(elmStr(FLD_TODO_SHARDINGKEY, todo.ShardingKey));
            result.Set(elmStr(FLD_TODO_PARALLELKEY, todo.ParallelKey));
            result.Set(new BSONInt32Element(FLD_TODO_PRIORITY, todo.Priority));
            result.Set(new BSONDateTimeElement(FLD_TODO_STARTDATE, todo.StartDate));
            result.Set(elmStr(FLD_TODO_CORRELATIONKEY, todo.CorrelationKey));
            result.Set(new BSONInt32Element(FLD_TODO_STATE, todo.State));
            result.Set(new BSONInt32Element(FLD_TODO_TRIES, todo.Tries));

            result.Set(new BSONInt32Element(FLD_TODO_SERIALIZER, todo.Serializer));
            result.Set(elmBin(FLD_TODO_CONTENT, todo.Content));

            return(result);
        }
示例#9
0
        private BSONDocument toBSONUpdate(TodoQueue queue, TodoFrame todo, bool sysOnly)
        {
            var setDoc = new BSONDocument();

            setDoc.Set(elmStr(FLD_TODO_SHARDINGKEY, todo.ShardingKey));
            setDoc.Set(elmStr(FLD_TODO_PARALLELKEY, todo.ParallelKey));
            setDoc.Set(new BSONInt32Element(FLD_TODO_PRIORITY, todo.Priority));
            setDoc.Set(new BSONDateTimeElement(FLD_TODO_STARTDATE, todo.StartDate));
            setDoc.Set(elmStr(FLD_TODO_CORRELATIONKEY, todo.CorrelationKey));
            setDoc.Set(new BSONInt32Element(FLD_TODO_STATE, todo.State));
            setDoc.Set(new BSONInt32Element(FLD_TODO_TRIES, todo.Tries));

            if (!sysOnly)
            {
                setDoc.Set(new BSONInt32Element(FLD_TODO_SERIALIZER, todo.Serializer));
                setDoc.Set(elmBin(FLD_TODO_CONTENT, todo.Content));
            }

            var result = new BSONDocument();

            result.Set(new BSONDocumentElement("$set", setDoc));

            return(result);
        }
示例#10
0
                                          private void executeOne(TodoQueue queue, TodoFrame todoFrame, DateTime utcNow)//must not leak
                                          {
                                              try
                                              {
                                                  if (!Running)
                                                  {
                                                      return;
                                                  }

                                                  Todo todo;
                                                  try
                                                  {
                                                      todo = todoFrame.Materialize(AgniSystem.ProcessManager.TodoTypeResolver);
                                                  }
                                                  catch (Exception me)
                                                  {
                                                      var from = "executeOne('{0}').Materialize".Args(queue.Name);
                                                      Log(MessageType.Critical, from, "Frame materialization: " + me.ToMessageWithType(), me);
                                                      if (InstrumentationEnabled)
                                                      {
                                                          m_stat_QueueOperationErrorCount.IncrementLong(ALL);
                                                          m_stat_QueueOperationErrorCount.IncrementLong(from);
                                                      }
                                                      throw;
                                                  }

                                                  var wasState = todo.SysState;
                                                  while (todo.SysState != Todo.ExecuteState.Complete)
                                                  {
                                                      var nextState = todo.Execute(this, utcNow);

                                                      if (nextState == Todo.ExecuteState.ReexecuteUpdatedAfterError)
                                                      {
                                                          todo.SysTries++;
                                                          var ms = todo.RetryAfterErrorInMs(utcNow);
                                                          if (ms > 0)
                                                          {
                                                              todo.SysStartDate = todo.SysStartDate.AddMilliseconds(ms);
                                                          }
                                                          update(queue, todo, false);
                                                          return;
                                                      }

                                                      if (nextState == Todo.ExecuteState.ReexecuteAfterError)
                                                      {
                                                          todo.SysTries++;
                                                          var ms = todo.RetryAfterErrorInMs(utcNow);
                                                          if (ms > 0)
                                                          {
                                                              todo.SysStartDate = todo.SysStartDate.AddMilliseconds(ms);
                                                          }
                                                          if (ms >= 0 || todo.SysState != wasState)
                                                          {
                                                              update(queue, todo, true);
                                                          }
                                                          return;
                                                      }

                                                      if (nextState == Todo.ExecuteState.ReexecuteUpdated)
                                                      {
                                                          update(queue, todo, false);
                                                          return;
                                                      }

                                                      if (nextState == Todo.ExecuteState.ReexecuteSysUpdated)
                                                      {
                                                          update(queue, todo, true);
                                                          return;
                                                      }

                                                      if (nextState == Todo.ExecuteState.Reexecute)
                                                      {
                                                          if (todo.SysState != wasState)
                                                          {
                                                              update(queue, todo, true);
                                                          }
                                                          return;
                                                      }

                                                      todo.SysTries = 0;
                                                      todo.SysState = nextState;
                                                  }

                                                  complete(queue, todoFrame, null);
                                              }
                                              catch (Exception error)
                                              {
                                                  complete(queue, todoFrame, error);
                                              }
                                          }
 private bool checkDupsInHostset(TodoQueue queue, TodoFrame todo)
 {
     return(false); // TODO implement
 }
 private bool checkDupsInMemory(TodoFrame todo)
 {
     return(!m_Duplicates.Put(todo.ID));
 }
示例#13
0
 public abstract void Complete(TodoQueue queue, TodoFrame todo, Exception error = null, object transaction = null);
示例#14
0
 public abstract void Put(TodoQueue queue, TodoFrame todo, object transaction);