Exemplo n.º 1
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("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();
            }
        }
        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();
            }
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        private void FailActivatedJob(IJob activatedJob, Exception exception)
        {
            string errorMessage = String.Format(JobFailMessage,
                                                activatedJob.Worker,
                                                activatedJob.Type,
                                                exception.Message);

            jobClient.NewFailCommand(activatedJob.Key)
            .Retries(activatedJob.Retries - 1)
            .ErrorMessage(errorMessage)
            .Send();
            Console.WriteLine(errorMessage);
        }