public void CollectMoneyHandler(IJobClient client, IJob activatedjob) { var variables = JsonConvert.DeserializeObject <Dictionary <string, object> >(activatedjob.Variables); CollectMoney(variables["orderId"].ToString(), (decimal)variables["amount"]); variables["test"] = "test"; }
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(); } }
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(); }
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; } }
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 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 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 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 HandleStockJob(IJobClient jobClient, IJob job) { Console.WriteLine("————流程进入:修改库存模块"); var variables = JsonConvert.DeserializeObject <Dictionary <string, object> >(job.Variables); var command = JsonConvert.DeserializeObject <StockCreateOrUpdateCommand>(variables["StockData"].ToString()); InitClient.StockManagementClient.CreateOrUpdateAsync(command).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(); }
public JobWorkerBuilder( Gateway.GatewayClient client, IJobClient jobClient, ILoggerFactory loggerFactory = null) { LoggerFactory = loggerFactory; Client = client; JobClient = jobClient; }
public JobWorkerBuilder(IZeebeClient zeebeClient, Gateway.GatewayClient gatewayClient, ILoggerFactory loggerFactory = null) { LoggerFactory = loggerFactory; Activator = new JobActivator(gatewayClient); Request = new ActivateJobsRequest(); JobClient = zeebeClient; ThreadCount = 1; }
internal JobWorker(Gateway.GatewayClient client, ActivateJobsRequest request, TimeSpan pollInterval, IJobClient jobClient, JobHandler jobHandler) { source = new CancellationTokenSource(); this.client = client; activeRequest = request; this.pollInterval = pollInterval; this.jobClient = jobClient; this.jobHandler = jobHandler; }
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(); }
public CancelOperationRequestCommandHandler( IJobClient jobClient, IAccountOperationRequestRepository accountOperationRequestRepository, IUnitOfWork unitOfWork, NotificationContext notificationContext) { _jobClient = jobClient ?? throw new ArgumentNullException(nameof(jobClient)); _accountOperationRequestRepository = accountOperationRequestRepository ?? throw new ArgumentNullException(nameof(accountOperationRequestRepository)); _unitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork)); _notificationContext = notificationContext ?? throw new ArgumentNullException(nameof(notificationContext)); }
public JobWorkerBuilder( IZeebeClient zeebeClient, ILoggerFactory loggerFactory = null) { LoggerFactory = loggerFactory; Command = (ActivateJobsCommand)zeebeClient.NewActivateJobsCommand(); JobClient = zeebeClient; ThreadCount = 1; zeebeClient.NewActivateJobsCommand(); }
internal JobWorker(Gateway.GatewayClient client, ActivateJobsRequest request, TimeSpan pollInterval, IJobClient jobClient, JobHandler jobHandler) { this.source = new CancellationTokenSource(); this.client = client; this.activator = new JobActivator(client); this.activeRequest = request; this.maxJobsActive = request.MaxJobsToActivate; this.pollInterval = pollInterval; this.jobClient = jobClient; this.jobHandler = jobHandler; }
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(); }
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(); } } }
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(); }
public JobWorkerBuilder(Gateway.GatewayClient client, IJobClient jobClient) { Client = client; JobClient = jobClient; }
public void ShipHandler(IJobClient client, IJob activatedjob) { var variables = JsonConvert.DeserializeObject <Dictionary <string, object> >(activatedjob.Variables); Ship(variables["test"].ToString()); }
private JobClientWrapper(IJobClient client) { Client = client; ClientWasUsed = false; }
public static JobClientWrapper Wrap(IJobClient client) { return(new JobClientWrapper(client)); }
public JobClientWrapper(IJobClient client) { Client = client; ClientWasUsed = false; }
public CurrencyRatesScheduler(ILogger <CurrencyRatesScheduler> logger, IJobClient jobClient, IServiceProvider serviceProvider) { _logger = logger; _jobClient = jobClient; _serviceProvider = serviceProvider; }
//private readonly IMediator mediator; public Demo(IBackgroundJobQueue _backgroundJobQueue, IJobClient _jobClient /*, IMediator _mediator*/) { jobClient = _jobClient; backgroundJobQueue = _backgroundJobQueue; //mediator = _mediator; }