Semaphore Acquire
semaphore_acquire · Nodes · Control
Acquires a named workflow semaphore slot before continuing.
Semaphore Acquire#
Blocks workflow execution until a semaphore permit is available, then passes through input data unchanged. Used as a workflow gate to control concurrency.
Overview#
The Semaphore Acquire node creates or uses an existing named semaphore and acquires a permit for the current job. If no permits are available, the node blocks (waits) until one becomes available or a configurable timeout occurs.
When the timeout occurs before acquiring a permit, the node executes the optional waiting workflow. This allows you to notify users or perform fallback actions when resources are busy. If no waiting workflow is connected, the node returns empty outputs.
Key Features:
- Blocks until permit is available or timeout occurs
- Configurable timeout with waiting workflow support
- Associates permits with job_id for automatic cleanup
- Supports key template interpolation for dynamic semaphore naming
- Passes through input data unchanged
When to Use#
Use Semaphore Acquire when you need to:
- Prevent race conditions (e.g., processing messages from the same user sequentially)
- Limit concurrent access to external APIs (rate limiting)
- Coordinate access to shared resources across workflows
- Implement mutual exclusion for critical sections
Configuration#
Fields#
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| key_template | String | Yes | - | Template for semaphore key. Use {{ field }} syntax for interpolation from input. |
| permits | Integer | No | 1 | Maximum number of permits for this semaphore (1-100). First acquire sets this permanently. |
| timeout_seconds | Integer | No | 30 | Timeout in seconds before executing waiting workflow (1-3600). Set to high value for near-indefinite wait. |
Key Template Interpolation#
The key_template supports dot-notation interpolation from the input object:
"telegram/{{ chat.id }}"with input{ "chat": { "id": "123" } }→"telegram/123""user/{{ user_id }}"with input{ "user_id": "456" }→"user/456""api-rate-limit"(no interpolation) →"api-rate-limit"
Inputs#
| Socket | Type | Required | Description |
|---|---|---|---|
| input | Any | Yes | Input data to pass through. Also used as context for key template interpolation. |
Outputs#
| Socket | Type | Description |
|---|---|---|
| output | Any | Same value as input (passthrough) |
| waiting | Any | Executes connected workflow when timeout occurs before permit acquisition |
Example: Telegram Message Handler#
Prevent processing multiple messages from the same chat concurrently:
{
"nodes": [
{
"id": "gate",
"type": "semaphore_acquire",
"config": {
"key_template": "telegram/{{ chat.id }}",
"permits": 1
},
"inputs": {
"input": "{{ trigger }}"
}
},
{
"id": "process",
"type": "ai_agent",
"inputs": {
"input": "{{ gate.output }}"
}
}
]
}
Execution Flow:
- Message arrives for chat.id = 123
- SemaphoreAcquire creates/acquires permit for key "telegram/123"
- If another job holds the permit, this node blocks until released or timeout occurs
- Once acquired, passes trigger data to process node
- When job completes, permit is automatically released
Example: API Rate Limiting#
Limit concurrent calls to an external API:
{
"nodes": [
{
"id": "rate_limit",
"type": "semaphore_acquire",
"config": {
"key_template": "external-api",
"permits": 5
},
"inputs": {
"input": "{{ trigger }}"
}
},
{
"id": "call_api",
"type": "http_get",
"inputs": {
"url": "https://api.example.com/data"
}
}
]
}
Note: Maximum 5 concurrent API calls across all jobs.
Example: Message Queueing with Timeout#
Show how to notify users when their message is queued:
{
"nodes": [
{
"id": "gate",
"type": "semaphore_acquire",
"config": {
"key_template": "telegram/{{ chat.id }}",
"permits": 1,
"timeout_seconds": 10
},
"inputs": {
"input": "{{ trigger }}"
}
},
{
"id": "notify_queued",
"type": "telegram_send",
"inputs": {
"chat_id": "{{ gate.waiting.chat.id }}",
"text": "Your message is queued and will be processed soon..."
}
},
{
"id": "process",
"type": "ai_agent",
"inputs": {
"input": "{{ gate.output }}"
}
}
]
}
Execution Flow:
- Message arrives while another message is being processed
- After 10 seconds without acquiring a permit, timeout occurs
- The
waitingoutput triggersnotify_queuedto inform the user - When the permit eventually becomes available,
outputtriggers processing
Automatic Cleanup#
Permits are automatically released when:
- The job completes successfully
- The job fails
- The job is cancelled
Explicit release via SemaphoreRelease node is optional.
Related Nodes#
- semaphore_release - Explicitly release a permit before job completion
Inputs
inputRequired
Outputs
outputwaiting
Configuration
| Field | Type | Required | Description |
|---|---|---|---|
key_template | text_block | Yes | Semaphore key template. Use {{ field }} for interpolation from input. |
permits | integer | No | Number of permits to acquire |
timeout_seconds | integer | No | Timeout in seconds before executing waiting workflow (1-3600) |
base_config | record | No | Shared node configuration. failure_mode decides what a failure of this node does to the workflow; leave it at the default stop unless the workflow handles the failure itself on the node's error output (route_to_error) or the node is a rare emergency kill switch (stop_workflow). |