Esempio n. 1
0
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var variables = JsonConvert.DeserializeObject <Dictionary <string, object> >(job.Variables);

            switch (job.Type)
            {
            case "collectmoney":
                string message = $"you have a order to pay! amount:{variables["amount"]}";
                Console.WriteLine($"OrderId:{variables["orderId"]},Function:{variables["func"]},message:{message}");
                jobClient.NewCompleteJobCommand(job.Key).Variables("{\"func\":\"handle stock and prepare delivery\",\"amount\":\"60\"}").Send();
                break;

            case "fetchitems":
                message = $"you should prepare cargoes! amount updated is:{variables["amount"]}";
                Console.WriteLine($"OrderId:{variables["orderId"]},Function:{variables["func"]},message:{message}");
                jobClient.NewCompleteJobCommand(job.Key).Variables("{\"func\":\"handle delivery and so on\"}").Send();
                break;

            case "shipparcel":
                Console.WriteLine($"OrderId:{variables["orderId"]},Function:{variables["func"]}");
                jobClient.NewCompleteJobCommand(job.Key).Send();
                break;

            default:
                Console.WriteLine($"OrderId:{variables["orderId"]},Function:default");
                break;
            }
        }
Esempio n. 2
0
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Handling job: " + job);

            if (jobKey % 3 == 0)
            {
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"foo\":2}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else if (jobKey % 2 == 0)
            {
                jobClient.NewFailCommand(jobKey)
                .Retries(job.Retries - 1)
                .ErrorMessage("Example fail")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else
            {
                // auto completion
            }
        }
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Worker 1 handling job: " + job);

            Thread.Sleep(3000);

            if (!test)
            {
                Console.WriteLine("Worker 1 completes job successfully.");
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"isk_account_id\":\"" + Guid.NewGuid() + "\"}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else
            {
                Console.WriteLine("Worker failing with message: {0}", "Backend system not available");
                jobClient.NewFailCommand(jobKey)
                .Retries(job.Retries - 1)
                .ErrorMessage("Backend system not available.")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
        }
Esempio n. 4
0
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Worker 2 handling job: " + job);

            Thread.Sleep(3000);

            if (!test)
            {
                Console.WriteLine("Worker 2 completes job successfully.");
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"isk_activated_done\":true}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else
            {
                Console.WriteLine("Worker 2 failing with message: {0}", "Activation Fault Message");
                jobClient.NewThrowErrorCommand(jobKey)
                .ErrorCode("Activation Fault")
                .ErrorMessage("Activation Fault Message")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
        }
        private async Task Handler(IJobClient client, IJob job)
        {
            _logger.LogInformation("Executing new plan");
            await Task.Delay(TimeSpan.FromSeconds(10));

            await client.NewCompleteJobCommand(job.Key).Send();
        }
Esempio n. 6
0
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Worker 3 handling job: " + job);

            Thread.Sleep(3000);

            if (test)
            {
                Console.WriteLine("Worker 3 will crash in 10 seconds ...");
                Thread.Sleep(10000);
                Environment.FailFast("Worker Crashed");
            }
            else
            {
                Console.WriteLine("Worker 3 completes job successfully.");
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"funds_allocated_done\":true}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
        }
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Handling job: " + job);

            Thread.Sleep(3000);

            if (!test || job.Retries == 1)
            {
                Console.WriteLine("Worker 5 completes job successfully.");
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"monthly_saving_done\":true}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else
            {
                Console.WriteLine("Worker 5 failing with message: {0}", "Backend system not available");
                jobClient.NewFailCommand(jobKey)
                .Retries(job.Retries - 1)
                .ErrorMessage("Backend system not available.")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
        }
Esempio n. 8
0
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Worker 4 handling job: " + job);

            Thread.Sleep(3000);

            JObject payload = JObject.Parse(job.Variables);

            Console.WriteLine("Account = {0}; Length = {1}", payload["source_account_id"], payload["source_account_id"].ToString().Length);

            if (!test || payload["source_account_id"].ToString().Length != 36)
            {
                Console.WriteLine("Worker 4 completes job successfully.");
                jobClient.NewCompleteJobCommand(jobKey)
                .Variables("{\"reccuring_transfer_done\":true}")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
            else
            {
                Console.WriteLine("Worker 4 failing with message: {0}", "Recurring Transfer Fault Message - Source account number is invalid.");
                jobClient.NewFailCommand(jobKey)
                .Retries(0)
                .ErrorMessage("Recurring Transfer Fault Message - Source account number is invalid.")
                .Send()
                .GetAwaiter()
                .GetResult();
            }
        }
        private static void JobHandler(IJobClient jobClient, IJob activatedJob)
        {
            var variables = JsonConvert.DeserializeObject <Dictionary <string, string> >(activatedJob.Variables);

            Log.LogInformation($"Sending email with message content: {variables[VariablesKey]}");

            jobClient.NewCompleteJobCommand(activatedJob).Send();
        }
        private async Task Handler(IJobClient client, IJob job)
        {
            _logger.LogInformation("Getting new price forecast from Wattsight API");
            await Task.Delay(TimeSpan.FromSeconds(2));

            _logger.LogInformation("Storing new price  forecast in Mesh Db");
            await Task.Delay(TimeSpan.FromSeconds(3));

            await client.NewCompleteJobCommand(job.Key).Send();
        }
Esempio n. 11
0
        private async Task Handler(IJobClient client, IJob job)
        {
            if (!_shutdown.IsCancellationRequested)
            {
                _logger.LogInformation($"Job name: {job.Type}");
                Console.WriteLine($"Current variables: {job.Variables}");

                await Task.Delay(2000, _shutdown.Token);

                var jobKey = job.Key;

                if (job.Type == "bar")
                {
                    var variables = new { foo = (jobKey % 3 == 0) ? 100 : 0 };
                    await client.NewCompleteJobCommand(jobKey).Variables(JsonConvert.SerializeObject(variables)).Send();
                }
                else
                {
                    await client.NewCompleteJobCommand(jobKey).Send();
                }
            }
        }
Esempio n. 12
0
        private async Task Handler(IJobClient client, IJob job)
        {
            _logger.LogInformation("Running new optimization based on updated price forecast");
            await Task.Delay(TimeSpan.FromSeconds(20));

            // random to see if it is better...
            var betterPlanFound = new Random().Next(1, 100) > 75 ? 1 : 0;
            var isItBetter      = betterPlanFound == 0 ? "No" : "Yes";
            var variables       = new { betterPlanFound };

            _logger.LogInformation($"Is the new plan better?  {isItBetter}");

            await client.NewCompleteJobCommand(job.Key).Variables(JsonConvert.SerializeObject(variables)).Send();
        }
        private static void HandleJob(IJobClient jobClient, IJob job)
        {
            Thread.Sleep(3000);

            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Handling job: " + job);
            Console.WriteLine("Worker completes job successfully.");
            jobClient.NewCompleteJobCommand(jobKey)
            .Variables("{\"case_id\":\"" + Guid.NewGuid() + "\"}")
            .Send()
            .GetAwaiter()
            .GetResult();
        }
Esempio n. 14
0
        public async void HandleJob(IJobClient jobClient, IJob job)
        {
            // business logic
            var jobKey = job.Key;

            Console.WriteLine("Handling job: " + job);

            Thread.Sleep(3000);

            var connection = new HubConnectionBuilder()
                             .WithUrl("https://localhost:5001/signalrhub", (opts) =>
            {
                opts.HttpMessageHandlerFactory = (message) =>
                {
                    if (message is HttpClientHandler clientHandler)
                    {
                        // bypass SSL certificate
                        clientHandler.ServerCertificateCustomValidationCallback +=
                            (sender, certificate, chain, sslPolicyErrors) => { return(true); }
                    }
                    ;
                    return(message);
                };
            })
                             .Build();

            await connection.StartAsync();

            WorkflowData variables = JsonConvert.DeserializeObject <WorkflowData>(job.Variables);

            await connection.InvokeCoreAsync("WorkflowStepDone", typeof(void), new object[] { job.WorkflowInstanceKey.ToString(), variables.connectionid, job.Type.ToString() });

            jobClient.NewCompleteJobCommand(jobKey)
            .Variables("")
            .Send()
            .GetAwaiter()
            .GetResult();
        }
 static void JobHandler(IJobClient jobClient, IJob activatedJob)
 {
     Console.WriteLine("Yeah, your request was approved and can now be ordered! Please celebrate accordingly!");
     jobClient.NewCompleteJobCommand(activatedJob).Send();
 }
Esempio n. 16
0
 private static async void HandleJob(IJobClient jobClient, IJob job)
 {
     // no actual send topic to redis and no ack on receive
     // from mico service
     await jobClient.NewCompleteJobCommand(job.Key).Send();
 }