TwP/servolux — Issue #9: No way to specify a run method always gets called every n seconds
Author: emschwar
Created: 2012-02-22 16:45:17+00:00
State: open

I have an application where I need to start my run loop at within 1 second of the 0th second of every minute. My first thought was to create a Servolux::Server with an interval of 60:

```
server = Servolux::Server.new("RunEveryMinute", :interval => 60)
server.include RunThisEveryMinute
server.start
```

but of course, the server's start method drifts by the duration of the start method every time it's invoked. I believe this is due to Servolux::Threaded::ThreadContainer's run method doing

```
sleep interval if running?
```

I can think of a couple of ways to get around this-- the simplest way I can think of would be to allow `interval`, here, to be a proc, and then we could do something like:

```
if interval.respond_to?(:call)
sleep interval.call if running?
else
sleep interval if running?
end
```

Then, for my application, I could do:

```
server = Servolux::Server.new("RunEveryMinute", :interval => lambda { 60 - (Time.now.sec) })
....
```

And that should, I think, give me what I want (namely, a run method that is invoked every 60 seconds).

Another option would be to give Servolux::Threaded::ThreadContainer a :strict_interval option (feel free to substitute a better name) that would make it do that calculation itself. That strikes me as a little harder for you to implement, but it might be a nicer API.