Scripting API: Queues

Part of the Scripting API reference.

The queue variable provides access to Message Queues from scripts. All methods are async.


Methods

Method Description
queue.get(name) Get queue handle: id, name + bound methods
queue.push(name, payload, priority?, ttlMs?) Push a message to the queue
queue.pull(name, count?) Pull messages (marks as processing)
queue.consume(name, count?) Consume messages (deletes immediately)
queue.peek(name, count?) Peek at messages without changing status
queue.ack(messageId) Acknowledge (delete) a processing message
queue.reject(messageId) Mark a message as failed
queue.requeue(messageId) Return a message to pending
queue.size(name) Get total message count
queue.stats(name) Get queue statistics (pending/processing/failed/total)
queue.recoverStuck(name) Return stuck processing messages to pending

Message lifecycle

push() -> [pending] -> pull() -> [processing] -> ack()    -> [deleted]
                                               -> reject() -> [failed]
                                               -> requeue() -> [pending]

push() -> [pending] -> consume() -> [deleted] (auto-ack)

peek, pull and consume only return pending messages. A failed message is counted by stats() but cannot be read back from a script - decide on a retry (requeue, or push a copy) while you still hold its id.

A message that stays in processing for more than 2 minutes without an acknowledgment is considered stuck; queue.recoverStuck(name) returns such messages to pending.


Message TTL

The optional ttlMs argument of push / pushFor says how long a message stays relevant, in milliseconds. It is stored as an absolute deadline, computed at push time.

// Relevant for one hour
queue.push("tasks", { action: "refresh" }, 0, 60 * 60 * 1000)

Once the deadline passes:

  • pull, consume and peek skip the message - it is never delivered, and never moves to processing;
  • it stops holding a slot: an expired message is never the reason a push fails with Queue is full, and queue.recoverStuck(name) deletes expired messages outright.

ttlMs must be a positive finite number; anything else raises an error. Omit it (or pass null) and the message never expires - the default, and the behavior of every message pushed without a TTL.


Examples

// Push a message
const msg = queue.push("notifications", { type: "email", to: "user@example.com" })
log(msg.id)

// Push with priority (higher = processed first)
queue.push("tasks", { action: "process" }, 10)

// Push with a time to live: relevant for one hour, then it expires
queue.push("tasks", { action: "refresh" }, 0, 60 * 60 * 1000)

// Pull and process
const messages = queue.pull("tasks", 5)
for (const m of messages) {
  log(m.payload)
  queue.ack(m.id)
}

// Consume (pull + auto-ack)
const consumed = queue.consume("events", 3)

// Peek without changing status
const peeked = queue.peek("tasks", 5)

// Get stats
const stats = queue.stats("tasks")
log(stats.pending, stats.processing, stats.failed)

// Return stuck processing messages to pending
queue.recoverStuck("tasks")

Queue handles (chaining)

queue.get(name) returns a handle - the queue id and name plus methods that already know the queue name:

const tasks = queue.get("tasks")

tasks.push({ action: "process" }, 10)
const messages = tasks.pull(5)
for (const m of messages) {
  log(m.payload)
  queue.ack(m.id)   // ack is addressed by message id, not by queue
}
log(tasks.size(), tasks.stats().pending)

A one-off call chains directly:

queue.get("tasks").push({ action: "process" })
Handle method Same as
push(payload, priority?, ttlMs?) queue.push(name, payload, priority?, ttlMs?)
pull(count?) queue.pull(name, count?)
consume(count?) queue.consume(name, count?)
peek(count?) queue.peek(name, count?)
size() queue.size(name)
stats() queue.stats(name)
recoverStuck() queue.recoverStuck(name)

ack, reject and requeue are not on the handle: they address a single message by id, not a queue.

queue.getFor(name, issue) returns a handle bound to both the queue and the issue; its methods call the *For variants, so the context is re-checked on every call:

const q = queue.getFor("project-queue", issue)
q.push({ data: "test" })   // = queue.pushFor("project-queue", issue, {...})
q.pull(5)

The getFor handle has no recoverStuck - there is no queue.recoverStuckFor.

Handles are just a different spelling of the flat calls: the flat API keeps working unchanged, and each handle method call counts against the queue call limit exactly like the flat call it delegates to. queue.get() / queue.getFor() themselves cost one call.


Context-aware methods (*For)

When a queue has a context configured (project/issue type restrictions), use *For methods. The issue parameter can be an issue object or a string key.

Method Description
queue.getFor(name, issue) Get handle with context check
queue.pushFor(name, issue, payload, priority?, ttlMs?) Push with context check
queue.pullFor(name, issue, count?) Pull with context check
queue.consumeFor(name, issue, count?) Consume with context check
queue.peekFor(name, issue, count?) Peek with context check
queue.sizeFor(name, issue) Size with context check
queue.statsFor(name, issue) Stats with context check
queue.ackFor(messageId, issue) Ack with context check
queue.rejectFor(messageId, issue) Reject with context check
queue.requeueFor(messageId, issue) Requeue with context check
queue.pushFor("project-queue", "PROJ-123", { data: "test" })
queue.pushFor("project-queue", issue, { data: "test" })

Limits

Limit Value
Max queue API calls per script 25
Max pull/consume count 10

Queue size limits (messages per queue, number of queues) are listed on the Limits page.


Next steps


JiBrok Studio for Jira Cloud JiBrok Studio for Jira Cloud
Release notes
Core Features
Triggers
Extensions
Data Storage
Scripting Overview
JavaScript Engine
Python Engine
Groovy Engine
Scripting API
Administration
Guides