Camunda.Api.Client icon indicating copy to clipboard operation
Camunda.Api.Client copied to clipboard

More samples

Open deman opened this issue 6 years ago • 5 comments

Hi,

It'd be very helpful if you could add more samples:

  1. how to start a process
  2. how to retrieve and complete task

Thank you.

deman avatar Jul 05 '18 05:07 deman

Indeed

I'd like to see a sample of how the FetchAndLock and then Complete work.

Thanks

aabuabdou avatar Nov 18 '18 16:11 aabuabdou

Indeed,

It is not clear how to complete the task

goremykin avatar Feb 26 '19 08:02 goremykin

To complete a task, I added to ExternalTaskService.cs:

public Task Complete(ExternalTaskInfo externalTask, CompleteExternalTask completeExternalTask) => _api.Complete(externalTask.Id, completeExternalTask);

Sample code, which checks, fetches and complete tasks for a certain topic:

private const string WorkerName = "MyWorker";
private const string TopicName = "MyTopic";

// build query
var externalTaskQuery = new ExternalTaskQuery() { Active = true, TopicName = TopicName };

// add some sorting
externalTaskQuery
    .Sort(ExternalTaskSorting.TaskPriority, SortOrder.Descending)
    .Sort(ExternalTaskSorting.LockExpirationTime);

// request external tasks according to query
List<ExternalTaskInfo> tasks = await camunda.ExternalTasks.Query(externalTaskQuery).List();

if (tasks.Any())
{
    var fetchedTasks = await camunda.ExternalTasks.FetchAndLock(new FetchExternalTasks()
    {
        AsyncResponseTimeout = 60 * 1000,
        MaxTasks = 1,
        WorkerId = WorkerName,
        Topics = new List<FetchExternalTaskTopic>() { new FetchExternalTaskTopic(TopicName, 1000) }
    });

    Console.WriteLine($"Fetched tasks: {fetchedTasks.Count}");

    if (fetchedTasks != null && fetchedTasks.Count > 0)
    {
        foreach (var fetched in fetchedTasks)
        {
            // Consider the task completed
            Console.WriteLine($"Completing task: {fetched.Id}");

            CompleteExternalTask completeExternalTask = new CompleteExternalTask() { WorkerId = WorkerName };
            await camunda.ExternalTasks.Complete(fetched, completeExternalTask);
        }
    }
}

DmitryKhi avatar Oct 29 '20 15:10 DmitryKhi

I don't see the Complete method for the ExternalTasks Library. I am using Camunda.Api.Clinet version 2.6.0. Also, where is extend lock?

bblair2018 avatar Mar 01 '21 21:03 bblair2018

Both reside in the ExternalTaskResource you get with ´camundaClient.ExternalTasks[id]´

gaensebluemchenritter avatar Jun 22 '21 17:06 gaensebluemchenritter