sidekiq-cron 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +67 -40
- data/lib/sidekiq/cron/job.rb +37 -33
- data/lib/sidekiq/cron/launcher.rb +1 -4
- data/lib/sidekiq/cron/locales/de.yml +15 -6
- data/lib/sidekiq/cron/locales/en.yml +14 -14
- data/lib/sidekiq/cron/locales/id.yml +15 -15
- data/lib/sidekiq/cron/locales/it.yml +15 -16
- data/lib/sidekiq/cron/locales/ja.yml +14 -10
- data/lib/sidekiq/cron/locales/pt.yml +14 -14
- data/lib/sidekiq/cron/locales/ru.yml +15 -7
- data/lib/sidekiq/cron/locales/zh-CN.yml +14 -11
- data/lib/sidekiq/cron/namespace.rb +0 -2
- data/lib/sidekiq/cron/poller.rb +1 -9
- data/lib/sidekiq/cron/schedule_loader.rb +1 -5
- data/lib/sidekiq/cron/support.rb +1 -2
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron/views/cron.erb +45 -49
- data/lib/sidekiq/cron/views/cron_show.erb +11 -11
- data/lib/sidekiq/cron/web.rb +12 -2
- data/lib/sidekiq/cron/web_extension.rb +44 -36
- data/lib/sidekiq/cron.rb +20 -8
- data/lib/sidekiq/options.rb +3 -5
- data/lib/sidekiq-cron.rb +6 -0
- data/sidekiq-cron.gemspec +2 -2
- metadata +13 -7
@@ -1,18 +1,22 @@
|
|
1
1
|
ja:
|
2
|
-
|
2
|
+
AreYouSureDeleteCronJob: 本当に%{job}のcronジョブを削除しますか?
|
3
|
+
AreYouSureDeleteCronJobs: 本当にすべてのcronジョブを削除しますか?
|
4
|
+
AreYouSureEnqueueCronJob: %{job} の クロン ジョブをキューに入れてもよろしいですか?
|
5
|
+
AreYouSureEnqueueCronJobs: すべての クロン ジョブをキューに入れてもよろしいですか?
|
3
6
|
Cron: Cron
|
4
7
|
CronJobs: Cronジョブ
|
5
|
-
|
6
|
-
|
8
|
+
CronString: Cron
|
9
|
+
DeleteAll: すべて削除
|
10
|
+
Description: 説明
|
11
|
+
Disable: 無効にする
|
7
12
|
DisableAll: すべて無効にする
|
13
|
+
Enable: 有効にする
|
14
|
+
EnableAll: すべて有効にする
|
8
15
|
EnqueueAll: すべてキューに入れる
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
AreYouSureDeleteCronJob: 本当に%{job}のcronジョブを削除しますか?
|
16
|
+
EnqueueNow: すぐにキューに入れる
|
17
|
+
Job: ジョブ
|
18
|
+
LastEnqueued: 最後のキュー
|
13
19
|
NoCronJobsWereFound: Cronジョブが見つかりませんでした
|
14
|
-
|
15
|
-
Disable: 無効にする
|
16
|
-
'Last enqueued': 最後のキュー
|
20
|
+
NoHistoryWereFound: 履歴が見つかりませんでした
|
17
21
|
disabled: 無効
|
18
22
|
enabled: 有効
|
@@ -1,22 +1,22 @@
|
|
1
1
|
pt:
|
2
|
-
|
2
|
+
AreYouSureDeleteCronJob: Tem certeza de que deseja excluir a tarefa %{job}?
|
3
|
+
AreYouSureDeleteCronJobs: Tem certeza de que deseja excluir TODOS as tarefas?
|
4
|
+
AreYouSureEnqueueCronJob: Tem certeza de que deseja enfileirar a tarefa %{job}?
|
5
|
+
AreYouSureEnqueueCronJobs: Tem certeza de que deseja enfileirar TODOS as tarefas?
|
3
6
|
Cron: Cron
|
4
7
|
CronJobs: Tarefas do Cron
|
5
|
-
|
6
|
-
|
8
|
+
CronString: Cron
|
9
|
+
DeleteAll: Excluir todos
|
10
|
+
Description: Descrição
|
11
|
+
Disable: Desabilitar
|
7
12
|
DisableAll: Desabilitar todos
|
13
|
+
Enable: Habilitar
|
14
|
+
EnableAll: Habilitar todos
|
8
15
|
EnqueueAll: Enfileirar todos
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
AreYouSureEnqueueCronJob: Tem certeza de que deseja enfileirar a tarefa %{job}?
|
13
|
-
AreYouSureDeleteCronJobs: Tem certeza de que deseja excluir TODOS as tarefas?
|
14
|
-
AreYouSureDeleteCronJob: Tem certeza de que deseja excluir a tarefa %{job}?
|
16
|
+
EnqueueNow: Enfileirar agora
|
17
|
+
Job: Tarefa
|
18
|
+
LastEnqueued: Último enfileirado
|
15
19
|
NoCronJobsWereFound: Nenhuma tarefa foi encontrada
|
16
|
-
|
17
|
-
Disable: Desabilitar
|
18
|
-
'Last enqueued': Último enfileirado
|
20
|
+
NoHistoryWereFound: Nenhum histórico foi encontrado
|
19
21
|
disabled: desabilitado
|
20
22
|
enabled: habilitado
|
21
|
-
NoHistoryWereFound: Nenhum histórico foi encontrado
|
22
|
-
Description: Descrição
|
@@ -1,14 +1,22 @@
|
|
1
1
|
ru:
|
2
|
-
|
2
|
+
AreYouSureDeleteCronJob: Вы действительно хотите удалить задачу «%{job}»?
|
3
|
+
AreYouSureDeleteCronJobs: Вы уверены, что хотите удалить ВСЕ cron-задачи?
|
4
|
+
AreYouSureEnqueueCronJob: Вы уверены, что хотите добавить в очередь cron-задачу %{job}?
|
5
|
+
AreYouSureEnqueueCronJobs: Вы уверены, что хотите добавить в очередь ВСЕ cron-задачи?
|
3
6
|
Cron: Cron
|
4
7
|
CronJobs: Периодические задачи
|
5
|
-
|
6
|
-
|
8
|
+
CronString: Периодичность (синтаксис Cron)
|
9
|
+
DeleteAll: Удалить все
|
10
|
+
Description: Описание
|
11
|
+
Disable: Отключить
|
12
|
+
DisableAll: Отключить все
|
13
|
+
Enable: Включить
|
14
|
+
EnableAll: Включить все
|
15
|
+
EnqueueAll: Добавить все в очередь
|
7
16
|
EnqueueNow: Запустить
|
8
|
-
|
17
|
+
Job: Задача
|
18
|
+
LastEnqueued: Последний запуск
|
9
19
|
NoCronJobsWereFound: Не найдено периодических задач
|
10
|
-
|
11
|
-
Disable: Отключить
|
12
|
-
'Last enqueued': Последний запуск
|
20
|
+
NoHistoryWereFound: История не найдена
|
13
21
|
disabled: отключено
|
14
22
|
enabled: включено
|
@@ -1,19 +1,22 @@
|
|
1
1
|
zh-CN:
|
2
|
-
|
2
|
+
AreYouSureDeleteCronJob: 你确定删除定时任务(%{job})吗?
|
3
|
+
AreYouSureDeleteCronJobs: 你确定删除所有的定时任务吗?
|
4
|
+
AreYouSureEnqueueCronJob: 您确定要将 %{job} 的 定时任务 任务加入队列吗?
|
5
|
+
AreYouSureEnqueueCronJobs: 您确定要将所有 定时任务 任务加入队列吗?
|
3
6
|
Cron: 定时任务
|
4
7
|
CronJobs: 定时任务列表
|
5
|
-
|
6
|
-
|
8
|
+
CronString: 定时策略
|
9
|
+
DeleteAll: 删除所有
|
10
|
+
Description: 描述
|
11
|
+
Disable: 禁用
|
7
12
|
DisableAll: 禁用所有
|
13
|
+
Enable: 启用
|
14
|
+
EnableAll: 启用所有
|
8
15
|
EnqueueAll: 执行所有
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
AreYouSureDeleteCronJob: 你确定删除定时任务(%{job})吗?
|
16
|
+
EnqueueNow: 立刻执行
|
17
|
+
Job: 任务
|
18
|
+
LastEnqueued: 放入队列时间
|
13
19
|
NoCronJobsWereFound: 没有定时任务
|
14
|
-
|
15
|
-
Disable: 禁用
|
16
|
-
'Last enqueued': 放入队列时间
|
20
|
+
NoHistoryWereFound: 未找到历史记录
|
17
21
|
disabled: 已禁用
|
18
22
|
enabled: 已启用
|
19
|
-
|
data/lib/sidekiq/cron/poller.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'sidekiq'
|
4
|
-
require 'sidekiq/cron'
|
5
3
|
require 'sidekiq/scheduled'
|
6
|
-
require 'sidekiq/options'
|
7
4
|
|
8
5
|
module Sidekiq
|
9
6
|
module Cron
|
10
7
|
# The Poller checks Redis every N seconds for scheduled cron jobs.
|
11
8
|
class Poller < Sidekiq::Scheduled::Poller
|
12
9
|
def initialize(config = nil)
|
13
|
-
if Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new('6.5.0')
|
14
|
-
# Old version of Sidekiq does not accept a config argument.
|
15
|
-
@config = config
|
16
|
-
end
|
17
|
-
|
18
10
|
super
|
19
11
|
end
|
20
12
|
|
@@ -40,7 +32,7 @@ module Sidekiq
|
|
40
32
|
private
|
41
33
|
|
42
34
|
def enqueue_job(job, time = Time.now.utc)
|
43
|
-
job.
|
35
|
+
job.test_and_enqueue_for_time! time if job && job.valid?
|
44
36
|
rescue => ex
|
45
37
|
# Problem somewhere in one job.
|
46
38
|
Sidekiq.logger.error "CRON JOB: #{ex.message}"
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require 'sidekiq'
|
2
|
-
require 'sidekiq/cron/job'
|
3
|
-
require 'sidekiq/options'
|
4
|
-
|
5
1
|
Sidekiq.configure_server do |config|
|
6
|
-
schedule_file = Sidekiq::
|
2
|
+
schedule_file = Sidekiq::Cron.configuration.cron_schedule_file
|
7
3
|
|
8
4
|
if File.exist?(schedule_file)
|
9
5
|
config.on(:startup) do
|
data/lib/sidekiq/cron/support.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# https://github.com/rails/rails/blob/352865d0f835c24daa9a2e9863dcc9dde9e5371a/activesupport/lib/active_support/inflector/methods.rb#L270
|
2
|
-
|
3
1
|
module Sidekiq
|
4
2
|
module Cron
|
5
3
|
module Support
|
4
|
+
# Inspired by Active Support Inflector
|
6
5
|
def self.constantize(camel_cased_word)
|
7
6
|
names = camel_cased_word.split("::".freeze)
|
8
7
|
|
data/lib/sidekiq/cron/version.rb
CHANGED
@@ -5,23 +5,23 @@
|
|
5
5
|
<small><%= @current_namespace %></small>
|
6
6
|
</h3>
|
7
7
|
</div>
|
8
|
-
<div class='col-sm-7 pull-right'
|
8
|
+
<div class='col-sm-7 pull-right h2'>
|
9
9
|
<% if @cron_jobs.size > 0 %>
|
10
10
|
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/delete" method="post" class="pull-right">
|
11
|
-
<%= csrf_tag
|
11
|
+
<%= csrf_tag %>
|
12
12
|
<input class="btn btn-danger" type="submit" name="delete" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSureDeleteCronJobs') %>" />
|
13
13
|
</form>
|
14
14
|
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/disable" method="post" class="pull-right">
|
15
|
-
<%= csrf_tag
|
16
|
-
<input class="btn btn-warn" type="submit" name="
|
15
|
+
<%= csrf_tag %>
|
16
|
+
<input class="btn btn-warn" type="submit" name="enqueue" value="<%= t('DisableAll') %>" />
|
17
17
|
</form>
|
18
18
|
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/enable" method="post" class="pull-right">
|
19
|
-
<%= csrf_tag
|
20
|
-
<input class="btn btn-warn" type="submit" name="
|
19
|
+
<%= csrf_tag %>
|
20
|
+
<input class="btn btn-warn" type="submit" name="enqueue" value="<%= t('EnableAll') %>" />
|
21
21
|
</form>
|
22
|
-
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/
|
23
|
-
<%= csrf_tag
|
24
|
-
<input class="btn btn-warn" type="submit" name="
|
22
|
+
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/enqueue" method="post" class="pull-right">
|
23
|
+
<%= csrf_tag %>
|
24
|
+
<input class="btn btn-warn" type="submit" name="enqueue" value="<%= t('EnqueueAll') %>" data-confirm="<%= t('AreYouSureEnqueueCronJobs') %>" />
|
25
25
|
</form>
|
26
26
|
<% end %>
|
27
27
|
</div>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<div class='row'>
|
32
32
|
<div class="col-sm-12 summary_bar">
|
33
33
|
<ul class="list-unstyled summary row">
|
34
|
-
<%
|
34
|
+
<% Sidekiq::Cron::Namespace.all_with_count.sort_by { |namespace| namespace[:name] }.each do |namespace| %>
|
35
35
|
<li class="col-sm-1">
|
36
36
|
<a href="<%= root_path %>cron/namespaces/<%= namespace[:name] %>">
|
37
37
|
<span class="count"><%= namespace[:count] %></span>
|
@@ -47,63 +47,59 @@
|
|
47
47
|
<% if @cron_jobs.size > 0 %>
|
48
48
|
<table class="table table-hover table-bordered table-striped table-white">
|
49
49
|
<thead>
|
50
|
+
<tr>
|
50
51
|
<th><%= t('Status') %></th>
|
51
|
-
<th><%= t('Name') %></th>
|
52
|
-
<th><%= t('
|
53
|
-
<th><%= t('
|
54
|
-
<th width="180"><%= t('Actions')%></th>
|
52
|
+
<th width="50%"><%= t('Name') %></th>
|
53
|
+
<th><%= t('CronString') %></th>
|
54
|
+
<th><%= t('LastEnqueued') %></th>
|
55
|
+
<th width="180"><%= t('Actions') %></th>
|
56
|
+
</tr>
|
55
57
|
</thead>
|
56
58
|
|
57
59
|
<tbody>
|
58
|
-
<% @cron_jobs.sort{|a,b| a.sort_name <=> b.sort_name }.
|
59
|
-
<%
|
60
|
+
<% @cron_jobs.sort{ |a,b| a.sort_name <=> b.sort_name }.each do |job| %>
|
61
|
+
<% klass = (job.status == 'disabled') ? 'bg-danger text-muted' : '' %>
|
62
|
+
<% escaped_job_name = CGI.escape(job.name).gsub('+', '%20') %>
|
60
63
|
<tr>
|
61
|
-
<td
|
62
|
-
<td
|
63
|
-
<a href="<%= root_path %>cron/namespaces/<%=
|
64
|
-
<b
|
64
|
+
<td class="<%= klass %>"><%= t job.status %></td>
|
65
|
+
<td class="<%= klass %>">
|
66
|
+
<a href="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>" title="<%= job.description %>">
|
67
|
+
<b class="<%= klass %>"><%= job.name %></b>
|
65
68
|
</a>
|
66
|
-
<
|
67
|
-
<small>
|
69
|
+
<br/>
|
68
70
|
<% if job.message and job.message.to_s.size > 100 %>
|
69
|
-
|
70
|
-
<
|
71
|
-
<
|
72
|
-
|
73
|
-
<% else %>
|
74
|
-
<button data-toggle="collapse" data-target=".worker_<%= index %>" class="btn btn-warn btn-xs"><%= t('ShowAll')%></button>
|
75
|
-
<div class="toggle worker_<%= index %>" style="display: inline;"><%= job.message[0..100] + "... " %></div>
|
76
|
-
<div class="toggle worker_<%= index %>" style="display: none;"><%= job.message %></div>
|
77
|
-
<% end %>
|
71
|
+
<details>
|
72
|
+
<summary class="btn btn-warn btn-xs">Show message</summary>
|
73
|
+
<p><small><%= job.message %></small></p>
|
74
|
+
</details>
|
78
75
|
<% else %>
|
79
|
-
|
76
|
+
<small><%= job.message %></small>
|
80
77
|
<% end %>
|
81
|
-
</small>
|
82
78
|
</td>
|
83
|
-
<td
|
84
|
-
<td
|
85
|
-
<td
|
79
|
+
<td class="<%= klass %>"><b><%= job.human_cron %><br/><small><%= job.cron.gsub(" ", " ") %></small></b></td>
|
80
|
+
<td class="<%= klass %>"><%= job.last_enqueue_time ? relative_time(job.last_enqueue_time) : "-" %></td>
|
81
|
+
<td class="<%= klass %>">
|
86
82
|
<% if job.status == 'enabled' %>
|
87
|
-
<form action="<%= root_path %>cron/namespaces/<%=
|
88
|
-
<%= csrf_tag
|
89
|
-
<input class='btn btn-warn btn-xs pull-left' type="submit" name="
|
83
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/enqueue" method="post">
|
84
|
+
<%= csrf_tag %>
|
85
|
+
<input class='btn btn-warn btn-xs pull-left' type="submit" name="enqueue" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => job.name) %>"/>
|
90
86
|
</form>
|
91
|
-
<form action="<%= root_path %>cron/namespaces/<%=
|
92
|
-
<%= csrf_tag
|
87
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/disable" method="post">
|
88
|
+
<%= csrf_tag %>
|
93
89
|
<input class='btn btn-warn btn-xs pull-left' type="submit" name="disable" value="<%= t('Disable') %>"/>
|
94
90
|
</form>
|
95
91
|
<% else %>
|
96
|
-
<form action="<%= root_path %>cron/namespaces/<%=
|
97
|
-
<%= csrf_tag
|
98
|
-
<input class='btn btn-warn btn-xs pull-left' type="submit" name="
|
92
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/enqueue" method="post">
|
93
|
+
<%= csrf_tag %>
|
94
|
+
<input class='btn btn-warn btn-xs pull-left' type="submit" name="enqueue" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => job.name) %>"/>
|
99
95
|
</form>
|
100
|
-
<form action="<%= root_path %>cron/namespaces/<%=
|
101
|
-
<%= csrf_tag
|
96
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/enable" method="post">
|
97
|
+
<%= csrf_tag %>
|
102
98
|
<input class='btn btn-warn btn-xs pull-left' type="submit" name="enable" value="<%= t('Enable') %>"/>
|
103
99
|
</form>
|
104
|
-
<form action="<%= root_path %>cron/namespaces/<%=
|
105
|
-
<%= csrf_tag
|
106
|
-
<input class='btn btn-xs btn-danger pull-left' type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => job.name) %>"/>
|
100
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/delete" method="post">
|
101
|
+
<%= csrf_tag %>
|
102
|
+
<input class='btn btn-xs btn-danger pull-left help-block' type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => job.name) %>"/>
|
107
103
|
</form>
|
108
104
|
<% end %>
|
109
105
|
</td>
|
@@ -5,25 +5,25 @@
|
|
5
5
|
<small><%= @job.name %></small>
|
6
6
|
</h3>
|
7
7
|
</div>
|
8
|
-
<div class="span col-sm-7 pull-right
|
8
|
+
<div class="span col-sm-7 pull-right h2">
|
9
9
|
<% cron_job_path = "#{root_path}cron/namespaces/#{@current_namespace}/jobs/#{CGI.escape(@job.name).gsub('+', '%20')}" %>
|
10
|
-
<form action="<%= cron_job_path %>/
|
11
|
-
<%= csrf_tag
|
12
|
-
<input class="btn btn-warn pull-left" name="
|
10
|
+
<form action="<%= cron_job_path %>/enqueue?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
11
|
+
<%= csrf_tag %>
|
12
|
+
<input class="btn btn-warn pull-left" name="enqueue" type="submit" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => @job.name) %>" />
|
13
13
|
</form>
|
14
14
|
<% if @job.status == 'enabled' %>
|
15
|
-
<form action="<%= cron_job_path %>/disable?redirect=<%= cron_job_path %>" method="post">
|
16
|
-
<%= csrf_tag
|
15
|
+
<form action="<%= cron_job_path %>/disable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
16
|
+
<%= csrf_tag %>
|
17
17
|
<input class="btn btn-warn pull-left" name="disable" type="submit" value="<%= t('Disable') %>" />
|
18
18
|
</form>
|
19
19
|
<% else %>
|
20
|
-
<form action="<%= cron_job_path %>/enable?redirect=<%= cron_job_path %>" method="post">
|
21
|
-
<%= csrf_tag
|
20
|
+
<form action="<%= cron_job_path %>/enable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
21
|
+
<%= csrf_tag %>
|
22
22
|
<input class="btn btn-warn pull-left" name="enable" type="submit" value="<%= t('Enable') %>" />
|
23
23
|
</form>
|
24
|
-
<form action="<%= cron_job_path %>/delete" method="post">
|
25
|
-
<%= csrf_tag
|
26
|
-
<input class="btn btn-danger" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => @job.name) %>" name="delete" type="submit" value="<%= t('Delete') %>" />
|
24
|
+
<form action="<%= cron_job_path %>/delete" class="pull-right" method="post">
|
25
|
+
<%= csrf_tag %>
|
26
|
+
<input class="btn btn-danger pull-left" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => @job.name) %>" name="delete" type="submit" value="<%= t('Delete') %>" />
|
27
27
|
</form>
|
28
28
|
<% end %>
|
29
29
|
</div>
|
data/lib/sidekiq/cron/web.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
require "sidekiq/cron/web_extension"
|
2
2
|
require "sidekiq/cron/job"
|
3
|
+
require "sidekiq/cron/namespace"
|
3
4
|
|
4
5
|
if defined?(Sidekiq::Web)
|
5
|
-
|
6
|
-
|
6
|
+
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.3.0')
|
7
|
+
Sidekiq::Web.register(
|
8
|
+
Sidekiq::Cron::WebExtension, # Class which contains the HTTP actions, required
|
9
|
+
name: "cron", # the name of the extension, used to namespace assets
|
10
|
+
tab: "Cron", # labels(s) of the UI tabs
|
11
|
+
index: "cron", # index route(s) for each tab
|
12
|
+
)
|
13
|
+
else
|
14
|
+
Sidekiq::Web.register Sidekiq::Cron::WebExtension
|
15
|
+
Sidekiq::Web.tabs["Cron"] = "cron"
|
16
|
+
end
|
7
17
|
end
|
@@ -4,68 +4,71 @@ module Sidekiq
|
|
4
4
|
def self.registered(app)
|
5
5
|
app.settings.locales << File.join(File.expand_path("..", __FILE__), "locales")
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
app.helpers do
|
8
|
+
# This method constructs the URL for the cron jobs page within the specified namespace.
|
9
|
+
def namespace_redirect_path
|
10
|
+
"#{root_path}cron/namespaces/#{route_params[:namespace]}"
|
11
|
+
end
|
10
12
|
|
11
|
-
|
13
|
+
def redirect_to_previous_or_default
|
14
|
+
redirect params['redirect'] || namespace_redirect_path
|
15
|
+
end
|
12
16
|
|
13
|
-
|
17
|
+
def render_erb(view)
|
18
|
+
views_path = File.join(File.expand_path("..", __FILE__), "views")
|
19
|
+
erb(File.read(File.join(views_path, "#{view}.erb")))
|
20
|
+
end
|
21
|
+
end
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
# Index page.
|
24
|
+
app.get '/cron' do
|
25
|
+
@current_namespace = 'default'
|
26
|
+
@cron_jobs = Sidekiq::Cron::Job.all(@current_namespace)
|
17
27
|
|
18
|
-
|
28
|
+
render_erb(:cron)
|
19
29
|
end
|
20
30
|
|
31
|
+
# Detail page for a specific namespace.
|
21
32
|
app.get '/cron/namespaces/:name' do
|
22
|
-
view_path = File.join(File.expand_path("..", __FILE__), "views")
|
23
|
-
|
24
33
|
@current_namespace = route_params[:name]
|
25
|
-
|
26
|
-
@namespaces = Sidekiq::Cron::Namespace.all_with_count
|
27
|
-
|
28
34
|
@cron_jobs = Sidekiq::Cron::Job.all(@current_namespace)
|
29
35
|
|
30
|
-
|
36
|
+
render_erb(:cron)
|
31
37
|
end
|
32
38
|
|
33
39
|
# Display job detail + jid history.
|
34
40
|
app.get '/cron/namespaces/:namespace/jobs/:name' do
|
35
|
-
view_path = File.join(File.expand_path("..", __FILE__), "views")
|
36
|
-
|
37
41
|
@current_namespace = route_params[:namespace]
|
38
|
-
@
|
39
|
-
|
40
|
-
@namespaces = Sidekiq::Cron::Namespace.all_with_count
|
41
|
-
|
42
|
-
@job = Sidekiq::Cron::Job.find(@job_name, @current_namespace)
|
42
|
+
@job = Sidekiq::Cron::Job.find(route_params[:name], @current_namespace)
|
43
43
|
|
44
44
|
if @job
|
45
|
-
|
45
|
+
render_erb(:cron_show)
|
46
46
|
else
|
47
|
-
redirect
|
47
|
+
redirect namespace_redirect_path
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
#
|
52
|
-
app.post '/cron/namespaces/:namespace/all/
|
53
|
-
Sidekiq::Cron::Job.all(route_params[:namespace]).each(&:
|
54
|
-
|
51
|
+
# Enqueue all cron jobs.
|
52
|
+
app.post '/cron/namespaces/:namespace/all/enqueue' do
|
53
|
+
Sidekiq::Cron::Job.all(route_params[:namespace]).each(&:enqueue!)
|
54
|
+
|
55
|
+
redirect_to_previous_or_default
|
55
56
|
end
|
56
57
|
|
57
58
|
# Enqueue cron job.
|
58
|
-
app.post '/cron/namespaces/:namespace/jobs/:name/
|
59
|
+
app.post '/cron/namespaces/:namespace/jobs/:name/enqueue' do
|
59
60
|
if job = Sidekiq::Cron::Job.find(route_params[:name], route_params[:namespace])
|
60
|
-
job.
|
61
|
+
job.enqueue!
|
61
62
|
end
|
62
|
-
|
63
|
+
|
64
|
+
redirect_to_previous_or_default
|
63
65
|
end
|
64
66
|
|
65
67
|
# Delete all schedules.
|
66
68
|
app.post '/cron/namespaces/:namespace/all/delete' do
|
67
69
|
Sidekiq::Cron::Job.all(route_params[:namespace]).each(&:destroy)
|
68
|
-
|
70
|
+
|
71
|
+
redirect_to_previous_or_default
|
69
72
|
end
|
70
73
|
|
71
74
|
# Delete schedule.
|
@@ -73,13 +76,15 @@ module Sidekiq
|
|
73
76
|
if job = Sidekiq::Cron::Job.find(route_params[:name], route_params[:namespace])
|
74
77
|
job.destroy
|
75
78
|
end
|
76
|
-
|
79
|
+
|
80
|
+
redirect_to_previous_or_default
|
77
81
|
end
|
78
82
|
|
79
83
|
# Enable all jobs.
|
80
84
|
app.post '/cron/namespaces/:namespace/all/enable' do
|
81
85
|
Sidekiq::Cron::Job.all(route_params[:namespace]).each(&:enable!)
|
82
|
-
|
86
|
+
|
87
|
+
redirect_to_previous_or_default
|
83
88
|
end
|
84
89
|
|
85
90
|
# Enable job.
|
@@ -87,13 +92,15 @@ module Sidekiq
|
|
87
92
|
if job = Sidekiq::Cron::Job.find(route_params[:name], route_params[:namespace])
|
88
93
|
job.enable!
|
89
94
|
end
|
90
|
-
|
95
|
+
|
96
|
+
redirect_to_previous_or_default
|
91
97
|
end
|
92
98
|
|
93
99
|
# Disable all jobs.
|
94
100
|
app.post '/cron/namespaces/:namespace/all/disable' do
|
95
101
|
Sidekiq::Cron::Job.all(route_params[:namespace]).each(&:disable!)
|
96
|
-
|
102
|
+
|
103
|
+
redirect_to_previous_or_default
|
97
104
|
end
|
98
105
|
|
99
106
|
# Disable job.
|
@@ -101,7 +108,8 @@ module Sidekiq
|
|
101
108
|
if job = Sidekiq::Cron::Job.find(route_params[:name], route_params[:namespace])
|
102
109
|
job.disable!
|
103
110
|
end
|
104
|
-
|
111
|
+
|
112
|
+
redirect_to_previous_or_default
|
105
113
|
end
|
106
114
|
end
|
107
115
|
end
|
data/lib/sidekiq/cron.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
require "sidekiq/cron/job"
|
2
|
-
require "sidekiq/cron/namespace"
|
3
|
-
require "sidekiq/cron/poller"
|
4
|
-
require "sidekiq/cron/launcher"
|
5
|
-
require "sidekiq/cron/schedule_loader"
|
6
|
-
|
7
1
|
module Sidekiq
|
8
2
|
module Cron
|
9
3
|
class << self
|
@@ -15,7 +9,22 @@ module Sidekiq
|
|
15
9
|
yield(configuration) if block_given?
|
16
10
|
end
|
17
11
|
|
12
|
+
def self.reset!
|
13
|
+
self.configuration = Configuration.new
|
14
|
+
end
|
15
|
+
|
18
16
|
class Configuration
|
17
|
+
# The interval, in seconds, at which to poll for scheduled cron jobs.
|
18
|
+
# This determines how frequently the scheduler checks for jobs to enqueue.
|
19
|
+
attr_accessor :cron_poll_interval
|
20
|
+
|
21
|
+
# The path to a YAML file containing multiple cron job schedules.
|
22
|
+
attr_accessor :cron_schedule_file
|
23
|
+
|
24
|
+
# The maximum number of recent cron job execution histories to retain.
|
25
|
+
# This value controls how many past job executions are stored.
|
26
|
+
attr_accessor :cron_history_size
|
27
|
+
|
19
28
|
# The default namespace is used when no namespace is specified.
|
20
29
|
attr_accessor :default_namespace
|
21
30
|
|
@@ -28,12 +37,15 @@ module Sidekiq
|
|
28
37
|
# The poller will not enqueue jobs that are late by more than this amount of seconds.
|
29
38
|
# Defaults to 60 seconds.
|
30
39
|
#
|
31
|
-
# This is useful when
|
32
|
-
# when the deployment is done and
|
40
|
+
# This is useful when Sidekiq (and Sidekiq-Cron) is not used in zero downtime deployments and
|
41
|
+
# when the deployment is done and Sidekiq-Cron starts to catch up, it will consider older
|
33
42
|
# jobs that missed their schedules during the deployment. E.g., jobs that run once a day.
|
34
43
|
attr_accessor :reschedule_grace_period
|
35
44
|
|
36
45
|
def initialize
|
46
|
+
@cron_poll_interval = 30
|
47
|
+
@cron_schedule_file = 'config/schedule.yml'
|
48
|
+
@cron_history_size = 10
|
37
49
|
@default_namespace = 'default'
|
38
50
|
@natural_cron_parsing_mode = :single
|
39
51
|
@reschedule_grace_period = 60
|
data/lib/sidekiq/options.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Module to access Sidekiq config
|
3
2
|
module Sidekiq
|
4
3
|
module Options
|
5
4
|
def self.[](key)
|
@@ -16,13 +15,12 @@ module Sidekiq
|
|
16
15
|
|
17
16
|
def self.options_field
|
18
17
|
return @options_field unless @options_field.nil?
|
18
|
+
|
19
19
|
sidekiq_version = Gem::Version.new(Sidekiq::VERSION)
|
20
20
|
@options_field = if sidekiq_version >= Gem::Version.new('7.0')
|
21
21
|
:default_configuration
|
22
|
-
elsif sidekiq_version >= Gem::Version.new('6.5')
|
23
|
-
false
|
24
22
|
else
|
25
|
-
|
23
|
+
false
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|