Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More samples #18

Open
deman opened this issue Jul 5, 2018 · 5 comments
Open

More samples #18

deman opened this issue Jul 5, 2018 · 5 comments

Comments

@deman
Copy link

deman commented Jul 5, 2018

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
Copy link

aabuabdou commented Nov 18, 2018

Indeed

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

Thanks

@goremykin
Copy link

Indeed,

It is not clear how to complete the task

@DmitryKhi
Copy link

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
Copy link

bblair2018 commented Mar 1, 2021

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants