Skip to main content

Lock

This task tries to publish a system-wide lock and will trigger the Yellow port if it succeeds.

An updatable value can be associated with a named lock, allowing you to use it securely as single/multi counters.

Unlock is done on either on end task, before triggering Green port, or will remain til removed or auto-deleted.

main

Lock name
A string representing the lock name. It is mandatory, and an error is thrown if missing. Size is limited to 50 of any characters.

If locked
Define the policy if a lock of same name is already published:

  • Wait: Wait until the current locking task terminates.
  • Raise error: Raise a standard error "lock_already_exists".
  • Stop task: Stop task execution without triggering any ports.

On end task
Defines if lock persist or not at the end of task execution.

Initial value
Lets you define an initial value when a named lock is used for the first time. It could be any JSON compatible object like integer, string, list or dictionary, and will be available at execution time under 'locked_value' in the current context.

Locked for (seconds)
If provided, defines the maximum of seconds where this lock is considered as Locked for others sequences

Delete after (days)
Number of days after last use before automatically releasing this lock.

Note:
If children tasks need to update 'locked_value', you have to export lock context through task key.

At unlock time (i.e. when all tasks triggered by yellow port are terminated, and before triggering green port), locked_value will be saved, and provided to the next agent/workflow acquiring this lock.

Example: single counter
sample2

This example demonstrates the use of Lock task to manage securely a multi agent/workflow counter:

  • Drop a Lock task from Control flow into workspace. This example assumes that task key is equal to "lock".
  • Let's define the Initial value.
{
"value": 0
}
  • Switch Lock task context access to "Through task key" in "Execution > Export context".

You are now able to access and update securely this counter from any tasks triggered by Yellow port. For example, to increment this counter by 1 in child task, use:

lock.lock_value.value +=1

where:

lock: Lock task key defined in Task info tab. lock_value.value: Value originally defined with Initial value, and always exported as lock_value.

After first Yellow port execution of this example, lock_value will be equal to 1. After the second one, it will be equal to 2, and so on.

After Yellow port execution and before calling green port, lock_value will be saved on server, and lock will be released.