Similar functionality to Automation's Queue #202
Answered
by
craigbarratt
Metriximor
asked this question in
Q&A
-
Hello, I'm just wondering if there is a way to implement a functionality similar to Home Assistant's Queue. I was wondering if there's a way to use unique but instead of killing other processes, it would put them on hold until the current one is finished |
Beta Was this translation helpful? Give feedback.
Answered by
craigbarratt
May 3, 2021
Replies: 1 comment
-
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") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Metriximor
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: