Module: Sidekiq::Cron::WebExtension

Defined in:
lib/sidekiq/cron/web_extension.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object


5
6
7
8
9
10
11
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/sidekiq/cron/web_extension.rb', line 5

def self.registered(app)

  app.settings.locales << File.join(File.expand_path("..", __FILE__), "locales")

  #index page of cron jobs
  app.get '/cron' do
    view_path    = File.join(File.expand_path("..", __FILE__), "views")

    @cron_jobs = Sidekiq::Cron::Job.all

    #if Slim renderer exists and sidekiq has layout.slim in views
    if defined?(Slim) && File.exists?(File.join(settings.views,"layout.slim"))
      render(:slim, File.read(File.join(view_path, "cron.slim")))
    else
      render(:erb, File.read(File.join(view_path, "cron.erb")))
    end
  end

  # display job detail + jid history
  app.get '/cron/:name' do
    view_path = File.join(File.expand_path("..", __FILE__), "views")

    @job = Sidekiq::Cron::Job.find(route_params[:name])
    if @job
      #if Slim renderer exists and sidekiq has layout.slim in views
      if defined?(Slim) && File.exists?(File.join(settings.views,"layout.slim"))
        render(:slim, File.read(File.join(view_path, "cron_show.slim")))
      else
        render(:erb, File.read(File.join(view_path, "cron_show.erb")))
      end
    else
      redirect "#{root_path}cron"
    end
  end

  #enque cron job
  app.post '/cron/:name/enque' do
    if route_params[:name] === '__all__'
      Sidekiq::Cron::Job.all.each(&:enque!)
    elsif job = Sidekiq::Cron::Job.find(route_params[:name])
      job.enque!
    end
    redirect params['redirect'] || "#{root_path}cron"
  end

  #delete schedule
  app.post '/cron/:name/delete' do
    if route_params[:name] === '__all__'
      Sidekiq::Cron::Job.all.each(&:destroy)
    elsif job = Sidekiq::Cron::Job.find(route_params[:name])
      job.destroy
    end
    redirect "#{root_path}cron"
  end

  #enable job
  app.post '/cron/:name/enable' do
    if route_params[:name] === '__all__'
      Sidekiq::Cron::Job.all.each(&:enable!)
    elsif job = Sidekiq::Cron::Job.find(route_params[:name])
      job.enable!
    end
    redirect params['redirect'] || "#{root_path}cron"
  end

  #disable job
  app.post '/cron/:name/disable' do
    if route_params[:name] === '__all__'
      Sidekiq::Cron::Job.all.each(&:disable!)
    elsif job = Sidekiq::Cron::Job.find(route_params[:name])
      job.disable!
    end
    redirect params['redirect'] || "#{root_path}cron"
  end

end