Zig for background job processing - update

Beanstalkz is the Zig client for Beanstalkd

fast general purpose work queue. The beauty of Beanstalkd is its absolute simplicity

Beanstalkd is supported by 67 client libraries on 21 programming languages.

In order to run background processing, you will use just 3 commands (from 11 supported)

  • submit(put) job into the queue
  • take(reserve) job from the queue for processing
  • delete job from the queue

Job lifecycle supported by beanstalkz

  'put' with delay                                'delete'             
  ----------------> [DELAYED] ---------------------------X
                        |     
                        | 'kick-job' or time passes
                        |              
  'put'                 v     'reserve'           'delete'
  -----------------> [READY] ---------> [RESERVED] ------X
                       |  ^                 |  
                       |  |                 | 'bury'
                       |  |   'kick-job'    v     'delete'
                       |   `------------ [BURIED]  ------X    
                       |                  
                       |                          'delete'
                        `--------------------------------X

Supported commands

Name Description API
use Set current tube(queue) use(tname: []const u8)
put Submit job to current tube put(pri: u32, delay: u32, ttr: u32, job: []const u8)
watch Subscribe to jobs submitted to the tube watch(tname: []const u8)
reserve Consume job reserve(timeout: u32, job: *Job)
bury Put job to the failed(“buried”) state bury(id: u32, pri: u32)
kick-job Put delayed or failed job to the ready state kick_job(id: u32)
ignore Un-subscribe ignore(tname: []const u8)
delete Remove job from the system delete(id: u32)
state Get job state state(id: u32)
connect Connect connect(allocator: Allocator, addr: ?[]const u8, port: ?u16)
disconnect Disconnect disconnect()

Zig version

0.16.0

For curious

If you don’t have experience using Beanstalkd, it’s a good idea to read:

or visit Beanstalkd repository

Note for mods

In my language, there’s a joke about people like me:

his hands grow from the wrong place

meaning I’m not great at hands-on work

So instead of “handmade,” I used “headmade"

2 Likes