# Zig for background job processing - update

**URL:** <https://ziggit.dev/t/zig-for-background-job-processing-update/7666>\
**Category:** Showcase\
**Tags:** io, zig-0-16, job-queue, headmade\
**Created:** [January 3, 2025, 1:20pm UTC](https://ziggit.dev/t/zig-for-background-job-processing-update/7666 "2025-01-03T13:20:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![g41797](https://ziggit.dev/user_avatar/ziggit.dev/g41797/32/3339_2.png) [@g41797](https://ziggit.dev/u/g41797)\
**Post date:** [January 3, 2025, 1:20pm UTC](https://ziggit.dev/t/zig-for-background-job-processing-update/7666/1 "2025-01-03T13:20:25Z")

</div>

[Beanstalkz](https://github.com/g41797/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

```txt
  '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](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L178) | Set current tube(queue) | [use(tname: []const u8)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.use) |
| [put](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L124) | Submit job to current tube | [put(pri: u32, delay: u32, ttr: u32, job: []const u8)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.put) |
| [watch](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L347) | Subscribe to jobs submitted to the tube | [watch(tname: []const u8)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.watch) |
| [reserve](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L203) | Consume job | [reserve(timeout: u32, job: \*Job)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.reserve) |
| [bury](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L310) | Put job to the failed(“buried”) state | [bury(id: u32, pri: u32)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.bury) |
| [kick-job](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L424) | Put delayed or failed job to the ready state | [kick\_job(id: u32)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.kick_job) |
| [ignore](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L363) | Un-subscribe | [ignore(tname: []const u8)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.ignore) |
| [delete](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L271) | Remove job from the system | [delete(id: u32)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.delete) |
| [state](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L465) | Get job state | [state(id: u32)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.state) |
| connect | Connect | [connect(allocator: Allocator, addr: ?[]const u8, port: ?u16)](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.connect) |
| [disconnect](https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt#L728) | Disconnect | [disconnect()](https://g41797.github.io/beanstalkz/#beanstalkz.client.Client.disconnect) |

## Zig version

0.16.0

## For curious

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

- [beanstalkd FAQ](https://pmatseykanets.github.io/beanstalkd-docs/resources/faq.html)
- [Giant Killing with Beanstalkd](https://www.sitepoint.com/giant-killing-with-beanstalkd/)
- [beanstalkd protocol](https://raw.githubusercontent.com/beanstalkd/beanstalkd/master/doc/protocol.txt)

or visit [Beanstalkd repository](https://github.com/beanstalkd/beanstalkd)

## 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**"
