ruby - Is sleep() a good idea for the main loop of a job-scheduling app -


I am writing a job-scheduling app in Ruby for my work (primarily on different protocols at different protocols To move files using)

My main loop looks like this:

  While true # some code to start the proper job sleep CONFIG ["Interval"]  

It's acting like a charm, but I'm not sure it's enough. With protected because running CPU-intensive software can run on a server.

Is there any other way to do the same thing, or sleep () is safe enough in my case?

The use of sleep for quick and dirty things is fine but for those things which are slightly stronger Or reliability is required. I suggest sleep is bad :) The problem with sleep is that thread (I'm assuming Windows here ...) is actually sleeping - the scheduler thread will not work, some of the sleep gap passes Until the time.

During this time the thread will not wake up anything. This means that it can not be canceled, or can wake up to take action on any kind of event. Of course, this process can be killed, but it does not give a chance to wake up the sleeping thread and clean up anything.

I am not familiar with Ruby, but I think there is a facility to wait on many things. If you can, then I suggest that instead of using sleep, you paint on two things

  1. A timer that wakes the thread from time to time to do its work .
  2. An event is set when it needs to cancel the process or consider quite (trapping C for example).

It will be better even when there is an incident that can be used to indicate the need to work. This will avoid voting on the timer. It usually leads to less resource usage and a more responsive system.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -