### Install Greenstalk Python Library Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/install.md Install the Greenstalk library using pip. ```bash pip install greenstalk ``` -------------------------------- ### Producer Example Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/index.md Example of a producer inserting a job into the queue. Requires the greenstalk library. ```python3 import greenstalk with greenstalk.Client(('127.0.0.1', 11300)) as client: client.put('hello') ``` -------------------------------- ### Install Beanstalkd on Debian/Ubuntu Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/install.md Install the Beanstalkd server on Debian or Ubuntu systems using apt. ```bash sudo apt install beanstalkd ``` -------------------------------- ### Install Beanstalkd on macOS Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/install.md Install the Beanstalkd server on macOS using Homebrew. ```bash brew install beanstalkd ``` -------------------------------- ### Quickstart: Basic Greenstalk Operations Source: https://github.com/justinmayhew/greenstalk/blob/main/README.rst This snippet demonstrates the fundamental usage of the Greenstalk client, including connecting to a beanstalkd server, putting a job onto the queue, reserving a job, accessing its properties, deleting it, and closing the client connection. Ensure a beanstalkd instance is running on the default host and port. ```pycon >>> import greenstalk >>> client = greenstalk.Client(('127.0.0.1', 11300)) >>> client.put('hello') 1 >>> job = client.reserve() >>> job.id 1 >>> job.body 'hello' >>> client.delete(job) >>> client.close() ``` -------------------------------- ### Consumer Example Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/index.md Example of a consumer reserving, processing, and deleting a job from the queue. Requires the greenstalk library. ```python3 import greenstalk with greenstalk.Client(('127.0.0.1', 11300)) as client: while True: job = client.reserve() print(job.body) client.delete(job) ``` -------------------------------- ### Import Greenstalk Library Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Start by importing the Greenstalk library to use its functionalities. ```pycon3 >>> import greenstalk ``` -------------------------------- ### Consumer: Receive and Deserialize JSON Job Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Example of a consumer reserving a job, deserializing the JSON string body, and extracting data. ```python3 job = client.reserve() payload = json.loads(job.body) send_registration_email(payload['user_id']) ``` -------------------------------- ### Producer: Send JSON Serialized Job Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Example of a producer serializing a Python dictionary to a JSON string before sending it as a job body. ```python3 payload = {'user_id': user_id} body = json.dumps(payload) client.put(body) ``` -------------------------------- ### Create a Greenstalk Client (Unix Domain Socket) Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Instantiate a Client object to connect to a beanstalkd server using a Unix domain socket path. ```pycon3 >>> client = greenstalk.Client('/var/run/beanstalkd/socket') ``` -------------------------------- ### Create a Greenstalk Client (TCP/IP) Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Instantiate a Client object to connect to a beanstalkd server running on a specific host and port using TCP/IP. ```pycon3 >>> client = greenstalk.Client(('127.0.0.1', 11300)) ``` -------------------------------- ### Reserve and Consume a Job Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Use the 'reserve' method to retrieve a job from the watch list. It blocks until a job is available or a timeout occurs. ```pycon3 >>> job = client.reserve() >>> job.id 1 >>> job.body 'hello' ``` -------------------------------- ### Insert a Job Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md Use the 'put' method to insert a job into the currently used tube. The job body is the only required argument. ```pycon3 >>> client.put('hello') 1 ``` -------------------------------- ### Delete a Reserved Job Source: https://github.com/justinmayhew/greenstalk/blob/main/docs/overview.md After successfully processing a job, use the 'delete' method to permanently remove it from the server. ```pycon3 >>> client.delete(job) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.