jlucansky / Camunda.Api.Client

Camunda REST API Client for .NET platform
MIT License
140 stars 77 forks source link

More samples #18

Open deman opened 6 years ago

deman commented 6 years ago

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.

aabuabdou commented 6 years ago

Indeed

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

Thanks

goremykin commented 5 years ago

Indeed,

It is not clear how to complete the task

DmitryKhi commented 4 years ago

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);
        }
    }
}
bblair2018 commented 3 years ago

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?

gaensebluemchenritter commented 3 years ago

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