Module: Wurk::Web::Enterprise::Periodic

Defined in:
lib/wurk/web/enterprise.rb

Overview

Periodic tab — list/pause/unpause/enqueue-now/history. The list view reuses Wurk::Cron::LoopSet; mutating actions write directly to the loops:{lid} HASH so they're idempotent and crash-safe.

Class Method Summary collapse

Class Method Details

.enqueue_now(lid) ⇒ Object

Spec §2.4 "enqueue-now": pushes a one-off run exactly as a tick would (Cron::Loop#job_item) — the worker's sidekiq_options, under the loop's own queue/retry. Returns the new jid, or nil when the loop doesn't exist.



217
218
219
220
221
222
# File 'lib/wurk/web/enterprise.rb', line 217

def enqueue_now(lid)
  loop_obj = fetch(lid)
  return nil unless loop_obj

  Wurk::Client.new.push(loop_obj.job_item)
end

.fetch(lid) ⇒ Object



201
202
203
# File 'lib/wurk/web/enterprise.rb', line 201

def fetch(lid)
  Wurk::Cron::LoopSet.new.fetch(lid)
end

.history(lid) ⇒ Object

Spec §8.0.1+: per-loop history list at loop-history:{lid}. Each entry is a [fired_at, jid] tuple (LPUSH'd by the poller).



226
227
228
229
230
231
# File 'lib/wurk/web/enterprise.rb', line 226

def history(lid)
  loop_obj = fetch(lid)
  return [] unless loop_obj

  loop_obj.history
end

.list ⇒ Object



197
198
199
# File 'lib/wurk/web/enterprise.rb', line 197

def list
  Wurk::Cron::LoopSet.new
end

.pause(lid) ⇒ Object



205
206
207
# File 'lib/wurk/web/enterprise.rb', line 205

def pause(lid)
  set_paused(lid, '1')
end

.set_paused(lid, value) ⇒ Object

rubocop:disable Naming/PredicateMethod



233
234
235
236
237
238
239
# File 'lib/wurk/web/enterprise.rb', line 233

def set_paused(lid, value) # rubocop:disable Naming/PredicateMethod
  loop_obj = fetch(lid)
  return false unless loop_obj

  Wurk.redis { |c| c.call('HSET', "#{Wurk::Cron::LOOP_PREFIX}#{lid}", 'paused', value) }
  true
end

.unpause(lid) ⇒ Object



209
210
211
# File 'lib/wurk/web/enterprise.rb', line 209

def unpause(lid)
  set_paused(lid, '0')
end