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 with the loop's configured klass/queue/args/retry. Returns the new jid, or nil when the loop doesn't exist.



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/wurk/web/enterprise.rb', line 100

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

  Wurk::Client.new.push(
    'class' => loop_obj.klass,
    'args' => loop_obj.args,
    'queue' => loop_obj.queue,
    'retry' => loop_obj.retry_value
  )
end

.fetch(lid) ⇒ Object



85
86
87
# File 'lib/wurk/web/enterprise.rb', line 85

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).



114
115
116
117
118
119
# File 'lib/wurk/web/enterprise.rb', line 114

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

  loop_obj.history
end

.listObject



81
82
83
# File 'lib/wurk/web/enterprise.rb', line 81

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

.pause(lid) ⇒ Object



89
90
91
# File 'lib/wurk/web/enterprise.rb', line 89

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

.set_paused(lid, value) ⇒ Object

rubocop:disable Naming/PredicateMethod



121
122
123
124
125
126
127
# File 'lib/wurk/web/enterprise.rb', line 121

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



93
94
95
# File 'lib/wurk/web/enterprise.rb', line 93

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