Skip to content

Instantly share code, notes, and snippets.

@sambatlim
Created March 18, 2024 07:10
Show Gist options
  • Save sambatlim/b9ca09b896bf106185ec4e476ac63861 to your computer and use it in GitHub Desktop.
Save sambatlim/b9ca09b896bf106185ec4e476ac63861 to your computer and use it in GitHub Desktop.
This gist shows you various ways to implement bullmq in python
import asyncio
from bullmq import Worker
async def process(job, job_token):
# job.data will include the data added to the queue
print(job.data)
return job.data
# return doSomethingAsync(job)
async def main():
# example connect redis that doesn't have username via Ip address
# worker = Worker("yourQueName", process, {"connection": "redis://:password@ip:port"})
# example connect redis that have username via Ip address
# worker = Worker("yourQueName", process, {"connection": "redis://username:password@ip:port"})
# example connect redis that doesn't have username via host (make sure your redis support rediss)
# worker = Worker("yourQueName", process, {"connection": "rediss://:password@yourhost.com:port"})
# example connect redis that have username via host (make sure your redis support rediss)
worker = Worker("yourQueName", process, {"connection": "rediss://username:password@yourhost.com:port"})
while True: # Add some breaking conditions here
await asyncio.sleep(1)
# When no need to process more jobs we should close the worker
await worker.close()
if __name__ == "__main__":
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment