Check if Queue is empty

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Vakarian
Posts: 2
Joined: Wednesday 25 November, 2020 - 01:49

Check if Queue is empty

Post by Vakarian »

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.

Code: Select all

if(
  ((time/60)-Label([time], (First(AtomByName([Orders], Model))))) <= 5,
  openic(1,c),
  openic(2,c)
)
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
User avatar
HarryBunnik
Posts: 361
Joined: Monday 07 February, 2011 - 11:22

Re: Check if Queue is empty

Post by HarryBunnik »

Hi David,

To see how many products are in a queue (or regardless what atom), you can request the content.

So Content(c) will return the number of products in the current atom (c).

But when I read your goal, I'm wondering if the MultiService atom is not more what you want to use (Library tree => Processes => MultiService). You can then use the CycleTime to calculate at what time the order can be released on to the cook. In the help some more information can be found how to use this atom.

I hope this idea helps,

Gr. Harry
Vakarian
Posts: 2
Joined: Wednesday 25 November, 2020 - 01:49

Re: Check if Queue is empty

Post by Vakarian »

Hello Harry,

thank you very much for your very quick Answer. I will try out your idea.

Gr. David
Post Reply