Esempio n. 1
0
        protected override void DoTask(WorkerBase.ActivityTask task)
        {
            string message;
            string destination;

            switch (task.ActivityName)
            {
            case "jobComplete":
                destination = GetInput <string>(task, "destination");
                Console.WriteLine($"Job {task.JobId} completed with destination = {destination}");
                RespondSuccess(task);
                break;

            case "jobFailed":
                message = GetInput <string>(task, "message") ?? "";
                Console.WriteLine($"Job {task.JobId} failed with message {message}");
                RespondSuccess(task);
                break;

            case "jobCancelled":
                Console.WriteLine($"Job {task.JobId} cancelled");
                RespondSuccess(task);
                break;

            default:
                RespondFailure(task, $"Unknown activity name - {task.ActivityName}");
                break;
            }
        }
        protected override void DoTask(WorkerBase.ActivityTask task)
        {
            if (task.ActivityName == "wait")
            {
                var signalName = (string)task.Input.SelectToken("signalName");
                var pollRate   = (int?)task.Input.SelectToken("pollRate") ?? defaultPollRate;

                if (string.IsNullOrWhiteSpace(signalName))
                {
                    RespondFailure(task, "Missing required signal name");
                }
                else
                {
                    Task.Run(() => WaitForSignal(task, signalName, pollRate));
                }
            }
        }
Esempio n. 3
0
 protected override void DoTask(WorkerBase.ActivityTask task)
 {
     try
     {
         RespondSuccess(task, ExecuteScript(task.Input));
     }
     catch (ScriptEngineException e)
     {
         logger.Error("Script error", e);
         RespondFailure(task, "Script failed with error: " + e.Message, e.ErrorDetails);
     }
     catch (Exception e)
     {
         logger.Error("Script error", e);
         RespondFailure(task, "Script failed with error: " + e.Message, e.StackTrace);
     }
 }
        private void WaitForSignal(WorkerBase.ActivityTask task, string signalName, int pollRate)
        {
            try
            {
                while (true)
                {
                    var signals = workflowClient.PollSignal(task.ExecutionId, signalName);
                    if (signals.Count == 0)
                    {
                        Thread.Sleep(pollRate * 1000);
                        continue;
                    }

                    if (signals.Count > 1)
                    {
                        logger.Warn("Wait task found more than one matching signal, ignoring all but the first");
                    }
                    var evt = signals[0]["attributes"];

                    switch ((string)evt["status"])
                    {
                    case "success":
                        RespondSuccess(task, evt["result"]);
                        return;

                    case "failure":
                        RespondFailure(task, (string)evt["reason"], evt["details"]);
                        return;

                    case "cancelled":
                        RespondCancelled(task);
                        return;

                    default:
                        RespondFailure(task, $"Invalid signal status - {evt["status"]}", evt);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Poll error - {ex.Message}  stack = {ex.StackTrace}");
                RespondFailure(task, $"Exception caught - {ex.Message}", ex.StackTrace);
            }
        }
Esempio n. 5
0
        protected override void DoNotification(WorkerBase.ActivityTask task)
        {
            var     notificationType = GetInput <string>(task, "type");
            string  reason;
            int     progress;
            JObject progressData;

            switch (notificationType)
            {
            case "ActivityTaskHeartbeat":
                progress     = GetInput <int>(task, "progress");
                progressData = GetInput <JObject>(task, "progressData", null);
                var overallProgress = -1;
                if (progressData != null)
                {
                    var stage  = (int)progressData.GetValue("stage");
                    var stages = (int)progressData.GetValue("stages");
                    overallProgress = ((stage - 1) * 100 + progress) / stages;
                }
                Console.WriteLine($"Job {task.JobId} progress = {progress} overall progress = {overallProgress}");
                break;

            case "WorkflowExecutionCancelledEvent":
                reason = GetInput <string>(task, "reason") ?? "";
                Console.WriteLine($"Job {task.JobId} errored with reason {reason}");
                break;

            case "WorkflowExecutionFailedEvent":
                reason = GetInput <string>(task, "reason") ?? "";
                Console.WriteLine($"Job {task.JobId} errored with reason {reason}");
                break;

            default:
                RespondFailure(task, $"Unknown notification type - {notificationType}");
                break;
            }
        }