~brightbox/brightbox/domtrix-packaging

« back to all changes in this revision

Viewing changes to lib/domtrix_core/keepalive.rb

  • Committer: Neil Wilson
  • Date: 2010-11-30 13:47:43 UTC
  • Revision ID: git-v1:e1201b75b8107fdf0ce1152cb01df41772f309e5
Initial commit of load balancer scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#       Brightbox - Statistic reporting classes
 
3
#       Copyright (C) 2010, Brightbox Systems
 
4
#       Author: Neil Wilson
 
5
#
 
6
# Simple keepalive class - triggers every minute
 
7
 
 
8
module DomtrixStats
 
9
  class Keepalive
 
10
 
 
11
    def initialize
 
12
      @trigger_time = Time.now
 
13
    end
 
14
 
 
15
    def action
 
16
      if triggered?
 
17
        @trigger_time = Time.now + 60
 
18
        yield nil, nil
 
19
      end
 
20
    end
 
21
 
 
22
    def triggered?
 
23
      Time.now >= @trigger_time
 
24
    end
 
25
 
 
26
  end
 
27
end