Skip to content
Discussion options

You must be logged in to vote

Async queues can provide some of this functionality. Here's an example where the processing task executes requests sequentially from a queue, and takes 10 seconds to process each one:

import asyncio

mesg_q = asyncio.Queue(0)

def send_message(text):
    mesg_q.put(text)
    
@time_trigger("startup")
def process_messages():
    task.unique("process_messages")
    while True:
        mesg = mesg_q.get()
        log.info(f"received mesg {mesg}")
        task.sleep(10)

# test code
send_message("message #1")
send_message("message #2")
send_message("message #3")

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Metriximor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants