Class: DBcron::Clock
Overview
nodoc
Instance Attribute Summary collapse
-
#stop ⇒ Object
Returns the value of attribute stop.
-
#tz ⇒ Object
readonly
Returns the value of attribute tz.
Instance Method Summary collapse
- #add_entry(name, cron, task) ⇒ Object
- #configure(opts = {}) ⇒ Object
-
#initialize ⇒ Clock
constructor
A new instance of Clock.
- #ready_tasks(time) ⇒ Object
- #start ⇒ Object
- #task_array ⇒ Object
Methods included from Actor
Constructor Details
Instance Attribute Details
#stop ⇒ Object
Returns the value of attribute stop.
99 100 101 |
# File 'lib/dbcron.rb', line 99 def stop @stop end |
#tz ⇒ Object (readonly)
Returns the value of attribute tz.
100 101 102 |
# File 'lib/dbcron.rb', line 100 def tz @tz end |
Instance Method Details
#add_entry(name, cron, task) ⇒ Object
115 116 117 |
# File 'lib/dbcron.rb', line 115 def add_entry(name, cron, task) @tasks[name] = CrontabEntry.new(name, cron: cron, task: task) end |
#configure(opts = {}) ⇒ Object
111 112 113 |
# File 'lib/dbcron.rb', line 111 def configure(opts = {}) @tz = opts[:tz] if opts[:tz] end |
#ready_tasks(time) ⇒ Object
119 120 121 |
# File 'lib/dbcron.rb', line 119 def ready_tasks(time) task_array.select { |e| e.ready?(time) } end |
#start ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/dbcron.rb', line 127 def start started_at = now host = Host.where(uuid: @uuid).first_or_create!( hostname: Socket.gethostname, pid: Process.pid, started: started_at, last_seen: started_at ) create(task_array) refresh(task_array) info "dbcron starting with #{worker_pool_size} workers" loop do start = now if start >= host.last_seen + HOST_ALIVE_TIME host.update_column(:last_seen, start) end tick(start) finish = now sleep_until_next_tick(finish) break if @stop end end |
#task_array ⇒ Object
123 124 125 |
# File 'lib/dbcron.rb', line 123 def task_array @task_array ||= @tasks.values end |