Class: Sidekiq::WebCustom::WebApp

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/web_custom/web_app.rb

Constant Summary collapse

MAPPED_TYPE =
{
  retries: RetrySet,
  scheduled: ScheduledSet,
}

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sidekiq/web_custom/web_app.rb', line 12

def self.registered(app)
  app.post '/queues/drain/:name' do
    timeout_params = {
      warn: Sidekiq::WebCustom.config.warn_execution_time,
      timeout: Sidekiq::WebCustom.config.max_execution_time,
      proc: ->(thread, seconds) { thread[Sidekiq::WebCustom::BREAK_BIT] = 1; Sidekiq.logger.warn "set bit #{thread[Sidekiq::WebCustom::BREAK_BIT]}" }
    }
    Thread.current[Sidekiq::WebCustom::BREAK_BIT] = nil
    ::Timeoutable.timeout(**timeout_params) do
      Sidekiq::Queue.new(params[:name]).drain(max: Sidekiq::WebCustom.config.drain_rate)
    end
    redirect_with_query("#{root_path}queues")
  end

  app.post '/job/delete' do
    parsed = parse_params(params['entry.score'])

    klass = MAPPED_TYPE[params['entry.type'].to_sym]
    job = klass.new.fetch(*parsed)&.first

    job&.delete
    redirect_with_query("#{root_path}scheduled")
  end

  app.post '/job/execute' do
    parsed = parse_params(params['entry.score'])

    klass = MAPPED_TYPE[params['entry.type'].to_sym]
    job = klass.new.fetch(*parsed)&.first

    status = job&.execute
    redirect_with_query("#{root_path}#{params['entry.type']}")
  end
end