### Put Task into Queue (Table Format) Source: https://github.com/moonlibs/xqueue/blob/master/README.md Add a task to the queue using table format, which requires the space format to be defined. This example shows a basic put operation. ```lua box.space.myqueue:put{ name="xxx"; data="yyy"; } ``` -------------------------------- ### Get Task Statistics Source: https://github.com/moonlibs/xqueue/blob/master/README.md Retrieves statistics for the queue, including counts of tasks in different states and transition information. This is useful for monitoring queue health and activity. ```sql box.space.queue:stats() ``` -------------------------------- ### XQueue Benchmark Results Source: https://github.com/moonlibs/xqueue/blob/master/README.md Benchmark results for producer operations, showing performance metrics like nanoseconds per operation and operations per second. ```bash ❯ .rocks/bin/luabench -d 1000000x Tarantool version: Tarantool 2.10.7-0-g60f7e18 Tarantool build: Darwin-arm64-RelWithDebInfo (static) Tarantool build flags: -Wno-unknown-pragmas -fexceptions -funwind-tables -fno-common -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong -fPIC -fmacro-prefix-map=/var/folders/8x/1m5v3n6d4mn62g9w_65vvt_r0000gn/T/tarantool_install1565297302=. -std=c11 -Wall -Wextra -Wno-strict-aliasing -Wno-char-subscripts -Wno-gnu-alignof-expression -Wno-cast-function-type CPU: Apple M1 @ 8 JIT: Enabled JIT: fold cse dce fwd dse narrow loop abc sink fuse Duration: 1000000 iters --- BENCH: 001_put_take_bench::bench_producer:producer-1 1000000 44046 ns/op 22703 op/s 4137 B/op +3946.04MB --- BENCH: 001_put_take_bench::bench_producer:producer-2 1000000 27519 ns/op 36339 op/s 4282 B/op +4084.35MB --- BENCH: 001_put_take_bench::bench_producer:producer-4 1000000 21510 ns/op 46491 op/s 4500 B/op +4291.69MB --- BENCH: 001_put_take_bench::bench_producer:producer-8 1000000 20804 ns/op 48068 op/s 4379 B/op +4176.26MB --- BENCH: 001_put_take_bench::bench_producer:producer-12 1000000 20383 ns/op 49062 op/s 4372 B/op +4169.59MB --- BENCH: 001_put_take_bench::bench_producer:producer-16 1000000 21495 ns/op 46523 op/s 4215 B/op +4019.98MB --- BENCH: 001_put_take_bench::bench_producer:producer-20 1000000 23676 ns/op 42238 op/s 4258 B/op +4061.49MB --- BENCH: 001_put_take_bench::bench_producer:producer-24 1000000 24456 ns/op 40891 op/s 4274 B/op +4076.65MB ``` -------------------------------- ### Put Task into Queue (Array Format) Source: https://github.com/moonlibs/xqueue/blob/master/README.md Add a task to the queue using array format. This format ignores the space format, and NULL should be used for ID generation. ```lua box.space.myqueue:put{ "xxx","yyy" } ``` -------------------------------- ### Put Task into Queue (Tuple Format) Source: https://github.com/moonlibs/xqueue/blob/master/README.md Add a task to the queue using a tuple. This format ignores space format and cannot be used with ID generation. ```lua box.space.myqueue:put(box.tuple.new{ 1,"xxx","yyy" }) ``` -------------------------------- ### XQueue Task Status Transitions Source: https://github.com/moonlibs/xqueue/blob/master/README.md Illustrates the possible state changes for a task within the XQueue system. Each transition is triggered by specific methods or actions. ```markdown | Transition | Description | |------------|---------------------------------------------------------------------------------------------| | X -> R | Task was put into the Queue into Ready state (method :put) | | X -> W | Task was put into the Queue into Waiting state (method :put with specified delay) | | W -> R | Task was scheduled by runat mechanism of the Queue and became ready to be Taken by consumer | | R -> T | Task was taken by consumer | | T -> W | Consumer returned task into the Queue and delayed its execution | | T -> R | Consumer returned task into the Queue for immediate execution | | T -> X | Consumer acknowledged successful execution of the Task, and task was removed from the Queue | | T -> Z | Consumer acknowledged successful execution of the Task, and task was moved to Zombie state for zombie_delay timeout | | T -> D | Consumer acknowledged successful execution of the Task, and task was moved to Done status and will be left in the Queue forever | | T -> S | Task was moved into another tube | | S -> R | Task was moved from another tube to be Ready | | S -> W | Task was moved from another tube to be Waiting | | S -> D | Task was moved from another tube to be Done | | S -> B | Task was moved from another tube to be Buried | ``` -------------------------------- ### Upgrade Tarantool Space to a Queue Source: https://github.com/moonlibs/xqueue/blob/master/README.md Use the M.upgrade function to imbue a Tarantool space with queueing capabilities. Configure format, fields, and features like auto-increment IDs, delayed tasks, and task retention. ```lua M.upgrade(space, { format = { -- space format. applied to space.format() if passed }, fields = { -- id is always taken from pk status = 'status_field_name' | status_field_no, runat = 'runat_field_name' | runat_field_no, priority = 'priority_field_name' | priority_field_no, }, features = { id = 'auto_increment' | 'time64' | 'uuid' | 'required' | function() ... return task_id end -- auto_increment - if pk is number, then use it for auto_increment -- uuid - if pk is string, then use uuid for id -- required - primary key MUST be present in tuple during put -- function - funciton will be called to aquire id for task retval = 'table' | 'tuple' -- table requires space format. default if applicable. a bit slower buried = true, -- if true, support bury/kick delayed = true, -- if true, support delayed tasks, requires `runat` keep = true, -- if true, keep ack'ed tasks in [D]one state, instead of deleting -- mutually exclusive with zombie zombie = true|number, -- requires `runat` field -- if number, then with default zombie delay, otherwise only if set delay during ack -- mutually exclusive with keep ttl = true|number, -- requires `runat` field -- Time To Live. Task is expired unless taken within time -- if number, then with default ttl, otherwise only if set during put/release ttr = true|number, -- requires `runat` field -- Time To Release. Task is returned into [R]eady unless processed (turned to ack|release from taken) within time -- if number, then with default ttl, otherwise only if set during take }, -- Set tubes for which statistics collector will be enabled tube_stats = { 'tube-1', 'tube-2' }, }) ``` -------------------------------- ### Upgrade Space to Queue Source: https://github.com/moonlibs/xqueue/blob/master/README.md Imbues a Tarantool space with queueing functionality. This method configures the space to manage tasks, supporting various features like delayed tasks, time-to-live, and task burying. ```APIDOC ## upgrade(space, options) ### Description Imbues a Tarantool space with the power of a queue. ### Parameters * **space**: The Tarantool space object to upgrade. * **options**: A table of configuration options for the queue. * **format**: (Optional) Defines the space format. Applied to `space.format()` if provided. * **fields**: (Optional) Maps queue-specific fields to space field names or numbers. * `status`: Field name or number for the task status. * `runat`: Field name or number for the task run-at time. * `priority`: Field name or number for the task priority. * **features**: (Optional) A table enabling various queue features: * `id`: Specifies how task IDs are generated. Options include `'auto_increment'`, `'time64'`, `'uuid'`, `'required'`, or a custom function. * `retval`: Specifies the return type for operations. Can be `'table'` or `'tuple'`. * `buried`: (Boolean) Enables support for `bury` and `kick` operations. * `delayed`: (Boolean) Enables support for delayed tasks, requires the `runat` field. * `keep`: (Boolean) If true, acknowledged tasks are kept in a 'done' state. Mutually exclusive with `zombie`. * `zombie`: (Boolean or Number) Enables zombie tasks. If a number, uses a default zombie delay. Requires the `runat` field. Mutually exclusive with `keep`. * `ttl`: (Boolean or Number) Enables Time To Live for tasks. If a number, uses a default TTL. Requires the `runat` field. * `ttr`: (Boolean or Number) Enables Time To Release for tasks. If a number, uses a default TTR. Requires the `runat` field. * **tube_stats**: (Optional) A table of tube names for which statistics collection will be enabled. ``` -------------------------------- ### Put Task with Delay and TTL Source: https://github.com/moonlibs/xqueue/blob/master/README.md Add a task with both a delay and a time-to-live (TTL). The task will wait for the delay and will be discarded if not taken before the TTL expires. ```lua box.space.myqueue:put({ name="xxx"; data="yyy"; }, { delay = 1.5; ttl = 100 }) ``` -------------------------------- ### Put Task into Queue Source: https://github.com/moonlibs/xqueue/blob/master/README.md Adds a task to the queue. The task can be provided as a table, array, or tuple, with options for delay and time-to-live. ```APIDOC ## space:put(task, attr) ### Description Adds a task to the queue. ### Parameters * **task**: The task data, which can be a table, array, or tuple. * **Table**: Requires space format. Suitable for ID generation. * **Array**: Ignores space format. Use `NULL` for ID generation. * **Tuple**: Ignores space format. Cannot be used with ID generation. * **attr**: (Optional) A table of attributes for the task. * **delay**: (Number) The number of seconds to delay before the task becomes ready. If set, the task state will be 'W' (waiting). * **ttl**: (Number) The number of seconds after which the task will be discarded if not taken. Requires the `runat` field. ``` -------------------------------- ### Put Task with Delay Source: https://github.com/moonlibs/xqueue/blob/master/README.md Add a task to the queue with a specified delay. The task will be in the 'Waiting' state until the delay has passed. ```lua box.space.myqueue:put({ name="xxx"; data="yyy"; }, { delay = 1.5 }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.