Пример #1
0
        public async Task ShouldCompleteWorkflow()
        {
            // given
            var handledJobs = new List <IJob>();

            // when
            using (zeebeClient.NewWorker()
                   .JobType("oneTask")
                   .Handler(async(jobClient, job) =>
            {
                await jobClient.NewCompleteJobCommand(job).Send();
                handledJobs.Add(job);
            })
                   .MaxJobsActive(1)
                   .Name("csharpWorker")
                   .Timeout(TimeSpan.FromSeconds(10))
                   .PollInterval(TimeSpan.FromMilliseconds(100))
                   .PollingTimeout(TimeSpan.FromSeconds(30L))
                   .Open())
            {
                var workflowInstance = await zeebeClient.NewCreateWorkflowInstanceCommand()
                                       .WorkflowKey(workflowKey)
                                       .WithResult()
                                       .Send();

                // then workflow was completed
                Assert.AreEqual(1, handledJobs.Count);

                Assert.AreEqual(workflowInstance.Version, 1);
                Assert.AreEqual(workflowKey, workflowInstance.WorkflowKey);
                Assert.AreEqual("oneTaskProcess", workflowInstance.BpmnProcessId);
                Assert.Greater(workflowInstance.WorkflowInstanceKey, 1);
            }
        }
Пример #2
0
        public async Task <WorkflowIdentifierResponse> StartWorkflow(string bpmProcessId)
        {
            var workflowInstance = await _client
                                   .NewCreateWorkflowInstanceCommand()
                                   .BpmnProcessId(bpmProcessId)
                                   .LatestVersion()
                                   .Send();

            return(new WorkflowIdentifierResponse(workflowInstance.WorkflowInstanceKey.ToString(), workflowInstance.Version));
        }
        private async Task BackgroundProceessing()
        {
            var i = 0;

            while (!_shutdown.IsCancellationRequested)
            {
                Console.WriteLine("Starting new instance of workflow");

                i++;
                var variables = new Dictionary <string, string>
                {
                    ["address"] = $"{i}[email protected]"
                };

                await _client
                .NewCreateWorkflowInstanceCommand()
                .BpmnProcessId("order-something")
                .LatestVersion()
                .Variables(JsonConvert.SerializeObject(variables))
                .Send();

                await Task.Delay(TimeSpan.FromSeconds(10), _shutdown.Token);

                //await Task.Delay(TimeSpan.FromDays(1), _shutdown.Token);
            }
        }
Пример #4
0
        public async Task ShouldCreateWorkflowInstance()
        {
            // given
            var deployResponse = await zeebeClient.NewDeployCommand()
                                 .AddResourceFile(DemoProcessPath)
                                 .Send();

            var workflowKey = deployResponse.Workflows[0].WorkflowKey;

            // when
            var workflowInstance = await zeebeClient
                                   .NewCreateWorkflowInstanceCommand()
                                   .WorkflowKey(workflowKey)
                                   .Variables(WorkflowInstanceVariables)
                                   .Send();

            // then
            Assert.AreEqual(workflowInstance.Version, 1);
            Assert.AreEqual(workflowKey, workflowInstance.WorkflowKey);
            Assert.AreEqual("demoProcess", workflowInstance.BpmnProcessId);
            Assert.Greater(workflowInstance.WorkflowInstanceKey, 1);
        }
        public async Task <String> StartWorkflowInstance(string bpmProcessId)
        {
            _logger.LogInformation("Starting workflow instance...");
            var instance = await _client.NewCreateWorkflowInstanceCommand()
                           .BpmnProcessId(bpmProcessId)
                           .LatestVersion()
                           .WithResult()
                           .Send();

            var jsonParams = new JSONParameters {
                ShowReadOnlyProperties = true
            };

            return(JSON.ToJSON(instance, jsonParams));
        }
Пример #6
0
        public async Task Send(dynamic variables)
        {
            // create zeebe client
            _client = ZeebeClient.NewZeebeClient(_zeebeUrl);
            // deploy
            var deployResponse = await _client.NewDeployCommand().AddResourceFile(_path).Send();

            // create workflow instance
            var workflowKey = deployResponse.Workflows[0].WorkflowKey;

            await _client
            .NewCreateWorkflowInstanceCommand()
            .WorkflowKey(workflowKey)
            .Variables(JsonConvert.SerializeObject(variables))
            .Send();
        }
Пример #7
0
        private static async Task GenerateMultiFlowInstances(long workflowKey)
        {
            for (var i = 0; i < WORK_COUNT; i++)
            {
                var variables = new
                {
                    orderId         = $"{DateTime.Now.Ticks}-{i}",
                    amount_instance = 20 + i,
                    func_instance   = "collect money for your orders"
                };
                await _client
                .NewCreateWorkflowInstanceCommand()

                .WorkflowKey(workflowKey)
                .Variables(JsonConvert.SerializeObject(variables))
                .Send();
            }
        }