Exemple #1
0
        public IRemoteTask CreateTask <T>([NotNull] T taskData, [CanBeNull] CreateTaskOptions createTaskOptions = null) where T : IRtqTaskData
        {
            createTaskOptions ??= new CreateTaskOptions();
            var type     = taskData.GetType();
            var taskId   = TimeGuid.NowGuid().ToGuid().ToString();
            var taskMeta = new TaskMetaInformation(TaskDataRegistry.GetTaskName(type), taskId)
            {
                Attempts          = 0,
                Ticks             = Timestamp.Now.Ticks,
                ParentTaskId      = string.IsNullOrEmpty(createTaskOptions.ParentTaskId) ? GetCurrentExecutingTaskId() : createTaskOptions.ParentTaskId,
                TaskGroupLock     = createTaskOptions.TaskGroupLock,
                State             = TaskState.New,
                MinimalStartTicks = 0,
            };
            var taskDataBytes = Serializer.Serialize(type, taskData);
            var task          = new Task(taskMeta, taskDataBytes);

            return(enableContinuationOptimization && localTaskQueue != null
                       ? new RemoteTaskWithContinuationOptimization(task, TaskTtl, HandleTaskCollection, localTaskQueue)
                       : new RemoteTask(task, TaskTtl, HandleTaskCollection));
        }