Check if Queue is empty
Posted: Wednesday 25 November, 2020 - 13:15
Hello,
I have a model where I have a Queue consisting of food orders and a server acting as a cook and preparing the orders from the queue.
Every order atom has a label "time" which represents the time the order has to be ready and the queue is orderd by that time, so that the orders which have to be ready at the earlierst time are in front of the queue. Now I want to add a restriction to the server so that he only starts to prepare orders which are due in under five minutes. I tried to put the following 4d Script into the "input startegy" of the server but this results in an error when the qeueue is empty because there is no atom to select with the "first()" function. The queue is connected to the first input channel.
Is there a way to check if the queue is empty to stop this error from occuring? Or is there a different way to achieve that the server only takes orders that are due in under five minutes?
Greetings,
David
I have a model where I have a Queue consisting of food orders and a server acting as a cook and preparing the orders from the queue.
Every order atom has a label "time" which represents the time the order has to be ready and the queue is orderd by that time, so that the orders which have to be ready at the earlierst time are in front of the queue. Now I want to add a restriction to the server so that he only starts to prepare orders which are due in under five minutes. I tried to put the following 4d Script into the "input startegy" of the server but this results in an error when the qeueue is empty because there is no atom to select with the "first()" function. The queue is connected to the first input channel.
Code: Select all
if(
((time/60)-Label([time], (First(AtomByName([Orders], Model))))) <= 5,
openic(1,c),
openic(2,c)
)
Greetings,
David