Example #1
0
        // In case if someone want to return tuple instead updated task...
        //public abstract (ConductorTaskStatus, String, String) ExecuteTask(ConductorTask task);

        /// <summary>
        /// Method that runs poll - ack - update cycle in a single thread.
        /// </summary>
        /// <param name="taskType">Task that should be processed ex. "task_1". </param>
        /// <param name="workerId">ID of a current worker. Use it if task that you want to poll has workerId assigned.</param>
        /// <param name="domain"></param>
        public void PollAndExecute(string taskType)
        {
            LogManager.GetCurrentClassLogger().Info("Starting poll and execute");

            while (IsRunning)
            {
                Thread.Sleep(PollingInterval);
                ConductorTask task = PollForSingleTask(taskType, WorkerId, Domain);

                if (task != null)
                {
                    LogManager.GetCurrentClassLogger().Info("Polled new task: " + JsonConvert.SerializeObject(task));

                    AckTask(task.TaskId, WorkerId);
                    ConductorTask processedTask = ExecuteTask(task);
                    UpdateTask(processedTask);
                    // In case if someone want to return tuple instead updated task...
                    // (ConductorTaskStatus status, String output, String logs) = ExecuteTask(task);
                    // UpdateTask(task, status, output);

                    // remove object after processing
                    processedTask = null;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Update task status. Use it if task has already set status, output and logs.
        /// </summary>
        /// <param name="task">Instance of conductor task. </param>
        /// <returns></returns>
        public string UpdateTask(ConductorTask task)
        {
            var request = new RestRequest($"tasks/", Method.POST);

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(task), ParameterType.RequestBody);

            var queryResult = Client.Execute(request);

            LogManager.GetCurrentClassLogger().Info("Updating task with ID: " + task.TaskId.ToString() + " . Result of update: " + queryResult.Content);

            return(queryResult.Content);
        }
Example #3
0
        /// <summary>
        /// Update task status, output and logs. Check ConductorTaskStatus to see available statuses.
        /// </summary>
        /// <param name="task">Instance of conductor task. </param>
        /// <param name="status">Status of conductor task. </param>
        /// <param name="output">Here you can pass parameters that task returned. </param>
        /// <returns></returns>
        public string UpdateTask(ConductorTask task, ConductorTaskStatus status, Dictionary <string, dynamic> output)
        {
            var request = new RestRequest($"tasks/", Method.POST);

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json");

            task.Status = status;
            task.Output = output;

            request.AddJsonBody(task);

            var queryResult = Client.Execute(request);

            LogManager.GetCurrentClassLogger().Info("Updating task with ID: " + task.TaskId.ToString() + " . Result of update: " + queryResult.Content);

            return(queryResult.Content);
        }
Example #4
0
 /// <summary>
 /// In this function you can process polled task.
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public abstract ConductorTask ExecuteTask(ConductorTask task);