Created
March 18, 2024 07:10
-
-
Save sambatlim/b9ca09b896bf106185ec4e476ac63861 to your computer and use it in GitHub Desktop.
This gist shows you various ways to implement bullmq in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://:[email protected]:port"}) | |
# example connect redis that have username via host (make sure your redis support rediss) | |
worker = Worker("yourQueName", process, {"connection": "rediss://username:[email protected]: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