From 4581331d7aa76a77c63101cbaf2bc633cd126116 Mon Sep 17 00:00:00 2001 From: Sabbir Ahmed Shameem <145862004+SAShameem@users.noreply.github.com> Date: Tue, 7 May 2024 22:10:18 +0600 Subject: [PATCH] Create worker.py --- .../examples/application/job/redis/worker.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 content/bn/examples/application/job/redis/worker.py diff --git a/content/bn/examples/application/job/redis/worker.py b/content/bn/examples/application/job/redis/worker.py new file mode 100644 index 0000000000..c3523a4e21 --- /dev/null +++ b/content/bn/examples/application/job/redis/worker.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import time +import rediswq + +host="redis" +# Uncomment next two lines if you do not have Kube-DNS working. +# import os +# host = os.getenv("REDIS_SERVICE_HOST") + +q = rediswq.RedisWQ(name="job2", host=host) +print("Worker with sessionID: " + q.sessionID()) +print("Initial queue state: empty=" + str(q.empty())) +while not q.empty(): + item = q.lease(lease_secs=10, block=True, timeout=2) + if item is not None: + itemstr = item.decode("utf-8") + print("Working on " + itemstr) + time.sleep(10) # Put your actual work here instead of sleep. + q.complete(item) + else: + print("Waiting for work") +print("Queue empty, exiting")