sidekiq-cron 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile +2 -2
- data/README.md +55 -6
- data/lib/sidekiq/cron/job.rb +13 -17
- data/lib/sidekiq/cron/namespace.rb +16 -21
- data/lib/sidekiq/cron/schedule_loader.rb +53 -12
- data/lib/sidekiq/cron/support.rb +4 -29
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron/views/cron.erb +96 -106
- data/lib/sidekiq/cron/views/cron_show.erb +86 -85
- data/lib/sidekiq/cron/views/legacy/cron.erb +113 -0
- data/lib/sidekiq/cron/views/legacy/cron_show.erb +92 -0
- data/lib/sidekiq/cron/web.rb +10 -1
- data/lib/sidekiq/cron/web_extension.rb +45 -24
- data/lib/sidekiq/cron.rb +12 -12
- data/sidekiq-cron.gemspec +2 -2
- metadata +9 -7
@@ -1,92 +1,93 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
<%=
|
12
|
-
<input class="btn btn-warn pull-left" name="enqueue" type="submit" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => @job.name) %>" />
|
13
|
-
</form>
|
14
|
-
<% if @job.status == 'enabled' %>
|
15
|
-
<form action="<%= cron_job_path %>/disable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
16
|
-
<%= csrf_tag %>
|
17
|
-
<input class="btn btn-warn pull-left" name="disable" type="submit" value="<%= t('Disable') %>" />
|
18
|
-
</form>
|
19
|
-
<% else %>
|
20
|
-
<form action="<%= cron_job_path %>/enable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
21
|
-
<%= csrf_tag %>
|
22
|
-
<input class="btn btn-warn pull-left" name="enable" type="submit" value="<%= t('Enable') %>" />
|
23
|
-
</form>
|
24
|
-
<form action="<%= cron_job_path %>/delete" class="pull-right" method="post">
|
1
|
+
<section>
|
2
|
+
<header>
|
3
|
+
<div>
|
4
|
+
<h2>
|
5
|
+
<%= "#{t('Cron')} #{t('Job')}" %>
|
6
|
+
<small><%= @job.name %></small>
|
7
|
+
</h2>
|
8
|
+
</div>
|
9
|
+
<form class="filter">
|
10
|
+
<% cron_job_path = "#{root_path}cron/namespaces/#{@current_namespace}/jobs/#{CGI.escape(@job.name).gsub('+', '%20')}" %>
|
11
|
+
<form action="<%= cron_job_path %>/enqueue?redirect=<%= cron_job_path %>" method="post">
|
25
12
|
<%= csrf_tag %>
|
26
|
-
<input class="btn btn-
|
13
|
+
<input class="btn btn-primary" name="enqueue" type="submit" value="<%= t('EnqueueNow') %>" data-confirm="<%= t('AreYouSureEnqueueCronJob', :job => @job.name) %>" />
|
27
14
|
</form>
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
<tr>
|
47
|
-
<th><%= t 'Description' %></th>
|
48
|
-
<td><%= @job.description %></td>
|
49
|
-
</tr>
|
50
|
-
<tr>
|
51
|
-
<th><%= t 'Message' %></th>
|
52
|
-
<td><pre><%= @job.pretty_message %></pre></td>
|
53
|
-
</tr>
|
54
|
-
<tr>
|
55
|
-
<th><%= t 'Cron' %></th>
|
56
|
-
<td><%= @job.cron.gsub(" ", " ") %></td>
|
57
|
-
</tr>
|
58
|
-
<tr>
|
59
|
-
<th><%= t 'Last enqueued' %></th>
|
60
|
-
<td><%= @job.last_enqueue_time ? relative_time(@job.last_enqueue_time) : "-" %></td>
|
61
|
-
</tr>
|
62
|
-
</tbody>
|
63
|
-
</table>
|
64
|
-
|
65
|
-
<header class="row">
|
66
|
-
<div class="col-sm-12">
|
67
|
-
<h4>
|
68
|
-
<%= t 'History' %>
|
69
|
-
</h4>
|
70
|
-
</div>
|
71
|
-
</header>
|
72
|
-
|
73
|
-
<% if @job.jid_history_from_redis.size > 0 %>
|
74
|
-
<table class="table table-hover table-bordered table-striped">
|
75
|
-
<thead>
|
76
|
-
<tr>
|
77
|
-
<th><%= t 'Enqueued' %></th>
|
78
|
-
<th><%= t 'JID' %></th>
|
79
|
-
</tr>
|
80
|
-
</thead>
|
15
|
+
<% if @job.status == 'enabled' %>
|
16
|
+
<form action="<%= cron_job_path %>/disable?redirect=<%= cron_job_path %>" method="post">
|
17
|
+
<%= csrf_tag %>
|
18
|
+
<input class="btn btn-primary" name="disable" type="submit" value="<%= t('Disable') %>" />
|
19
|
+
</form>
|
20
|
+
<% else %>
|
21
|
+
<form action="<%= cron_job_path %>/enable?redirect=<%= cron_job_path %>" method="post">
|
22
|
+
<%= csrf_tag %>
|
23
|
+
<input class="btn btn-primary" name="enable" type="submit" value="<%= t('Enable') %>" />
|
24
|
+
</form>
|
25
|
+
<form action="<%= cron_job_path %>/delete" method="post">
|
26
|
+
<%= csrf_tag %>
|
27
|
+
<input class="btn btn-danger" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => @job.name) %>" name="delete" type="submit" value="<%= t('Delete') %>" />
|
28
|
+
</form>
|
29
|
+
<% end %>
|
30
|
+
</form>
|
31
|
+
</header>
|
32
|
+
<table class="table table-bordered table-striped">
|
81
33
|
<tbody>
|
82
|
-
<% @job.jid_history_from_redis.each do |jid_history| %>
|
83
34
|
<tr>
|
84
|
-
<
|
85
|
-
<td><%=
|
35
|
+
<th><%= t 'Status' %></th>
|
36
|
+
<td><%= @job.status %></td>
|
37
|
+
</tr>
|
38
|
+
<tr>
|
39
|
+
<th><%= t 'Name' %></th>
|
40
|
+
<td><%= @job.name %></td>
|
41
|
+
</tr>
|
42
|
+
<tr>
|
43
|
+
<th><%= t 'Namespace' %></th>
|
44
|
+
<td><%= @job.namespace %></td>
|
45
|
+
</tr>
|
46
|
+
<tr>
|
47
|
+
<th><%= t 'Description' %></th>
|
48
|
+
<td><%= @job.description %></td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<th><%= t 'Message' %></th>
|
52
|
+
<td>
|
53
|
+
<pre><%= @job.pretty_message %></pre>
|
54
|
+
</td>
|
55
|
+
</tr>
|
56
|
+
<tr>
|
57
|
+
<th><%= t 'Cron' %></th>
|
58
|
+
<td><%= @job.cron.gsub(" ", " ") %></td>
|
59
|
+
</tr>
|
60
|
+
<tr>
|
61
|
+
<th><%= t 'Last enqueued' %></th>
|
62
|
+
<td><%= @job.last_enqueue_time ? relative_time(@job.last_enqueue_time) : "-" %></td>
|
86
63
|
</tr>
|
87
|
-
<% end %>
|
88
64
|
</tbody>
|
89
65
|
</table>
|
90
|
-
|
91
|
-
|
92
|
-
|
66
|
+
<header>
|
67
|
+
<div>
|
68
|
+
<h4>
|
69
|
+
<%= t 'History' %>
|
70
|
+
</h4>
|
71
|
+
</div>
|
72
|
+
</header>
|
73
|
+
<% if @job.jid_history_from_redis.size > 0 %>
|
74
|
+
<table class="table table-hover table-bordered table-striped">
|
75
|
+
<thead>
|
76
|
+
<tr>
|
77
|
+
<th><%= t 'Enqueued' %></th>
|
78
|
+
<th><%= t 'JID' %></th>
|
79
|
+
</tr>
|
80
|
+
</thead>
|
81
|
+
<tbody>
|
82
|
+
<% @job.jid_history_from_redis.each do |jid_history| %>
|
83
|
+
<tr>
|
84
|
+
<td><%= jid_history['enqueued'] %></td>
|
85
|
+
<td><%= jid_history['jid'] %></td>
|
86
|
+
</tr>
|
87
|
+
<% end %>
|
88
|
+
</tbody>
|
89
|
+
</table>
|
90
|
+
<% else %>
|
91
|
+
<div class='alert alert-success'><%= t 'NoHistoryWereFound' %></div>
|
92
|
+
<% end %>
|
93
|
+
</section>
|
@@ -0,0 +1,113 @@
|
|
1
|
+
<header class='row'>
|
2
|
+
<div class='col-sm-5 pull-left'>
|
3
|
+
<h3>
|
4
|
+
<%= t('CronJobs') %>
|
5
|
+
<small><%= @current_namespace %></small>
|
6
|
+
</h3>
|
7
|
+
</div>
|
8
|
+
<div class='col-sm-7 pull-right h2'>
|
9
|
+
<% if @cron_jobs.size > 0 %>
|
10
|
+
<form action="<%= root_path %>cron/namespaces/<%= @current_namespace %>/all/delete" method="post" class="pull-right">
|
11
|
+
<%= csrf_tag %>
|
12
|
+
<input class="btn btn-danger" type="submit" name="delete" value="<%= t('DeleteAll') %>" data-confirm="<%= t('AreYouSureDeleteCronJobs') %>" />
|
13
|
+
</form>
|
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="enqueue" value="<%= t('DisableAll') %>" />
|
17
|
+
</form>
|
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="enqueue" value="<%= t('EnableAll') %>" />
|
21
|
+
</form>
|
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
|
+
</form>
|
26
|
+
<% end %>
|
27
|
+
</div>
|
28
|
+
</header>
|
29
|
+
|
30
|
+
<!-- Namespaces -->
|
31
|
+
<div class='row'>
|
32
|
+
<div class="col-sm-12 summary_bar">
|
33
|
+
<ul class="list-unstyled summary row">
|
34
|
+
<% Sidekiq::Cron::Namespace.all_with_count.sort_by { |namespace| namespace[:name] }.each do |namespace| %>
|
35
|
+
<li class="col-sm-1">
|
36
|
+
<a href="<%= root_path %>cron/namespaces/<%= namespace[:name] %>">
|
37
|
+
<span class="count"><%= namespace[:count] %></span>
|
38
|
+
<span class="desc"><%= namespace[:name] %></span>
|
39
|
+
</a>
|
40
|
+
</li>
|
41
|
+
<% end %>
|
42
|
+
</ul>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
<!-- Namespaces -->
|
46
|
+
|
47
|
+
<% if @cron_jobs.size > 0 %>
|
48
|
+
<table class="table table-hover table-bordered table-striped table-white">
|
49
|
+
<thead>
|
50
|
+
<tr>
|
51
|
+
<th><%= t('Status') %></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>
|
57
|
+
</thead>
|
58
|
+
|
59
|
+
<tbody>
|
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') %>
|
63
|
+
<tr>
|
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>
|
68
|
+
</a>
|
69
|
+
<br/>
|
70
|
+
<% if job.message and job.message.to_s.size > 100 %>
|
71
|
+
<details>
|
72
|
+
<summary class="btn btn-warn btn-xs">Show message</summary>
|
73
|
+
<p><small><%= job.message %></small></p>
|
74
|
+
</details>
|
75
|
+
<% else %>
|
76
|
+
<small><%= job.message %></small>
|
77
|
+
<% end %>
|
78
|
+
</td>
|
79
|
+
<td class="<%= klass %>"><b><%= job.human_cron %><br/><small><%= job.cron_expression_string.gsub(" ", " ") %></small></b></td>
|
80
|
+
<td class="<%= klass %>"><%= job.last_enqueue_time ? relative_time(job.last_enqueue_time) : "-" %></td>
|
81
|
+
<td class="<%= klass %>">
|
82
|
+
<% if job.status == 'enabled' %>
|
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) %>"/>
|
86
|
+
</form>
|
87
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/disable" method="post">
|
88
|
+
<%= csrf_tag %>
|
89
|
+
<input class='btn btn-warn btn-xs pull-left' type="submit" name="disable" value="<%= t('Disable') %>"/>
|
90
|
+
</form>
|
91
|
+
<% else %>
|
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) %>"/>
|
95
|
+
</form>
|
96
|
+
<form action="<%= root_path %>cron/namespaces/<%= job.namespace %>/jobs/<%= escaped_job_name %>/enable" method="post">
|
97
|
+
<%= csrf_tag %>
|
98
|
+
<input class='btn btn-warn btn-xs pull-left' type="submit" name="enable" value="<%= t('Enable') %>"/>
|
99
|
+
</form>
|
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) %>"/>
|
103
|
+
</form>
|
104
|
+
<% end %>
|
105
|
+
</td>
|
106
|
+
</tr>
|
107
|
+
<% end %>
|
108
|
+
</tbody>
|
109
|
+
</table>
|
110
|
+
<% else %>
|
111
|
+
<div class='alert alert-success'><%= t('NoCronJobsWereFound') %></div>
|
112
|
+
<% end %>
|
113
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
<header class="row">
|
2
|
+
<div class="span col-sm-5 pull-left">
|
3
|
+
<h3>
|
4
|
+
<%= "#{t('Cron')} #{t('Job')}" %>
|
5
|
+
<small><%= @job.name %></small>
|
6
|
+
</h3>
|
7
|
+
</div>
|
8
|
+
<div class="span col-sm-7 pull-right h2">
|
9
|
+
<% cron_job_path = "#{root_path}cron/namespaces/#{@current_namespace}/jobs/#{CGI.escape(@job.name).gsub('+', '%20')}" %>
|
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
|
+
</form>
|
14
|
+
<% if @job.status == 'enabled' %>
|
15
|
+
<form action="<%= cron_job_path %>/disable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
16
|
+
<%= csrf_tag %>
|
17
|
+
<input class="btn btn-warn pull-left" name="disable" type="submit" value="<%= t('Disable') %>" />
|
18
|
+
</form>
|
19
|
+
<% else %>
|
20
|
+
<form action="<%= cron_job_path %>/enable?redirect=<%= cron_job_path %>" class="pull-right" method="post">
|
21
|
+
<%= csrf_tag %>
|
22
|
+
<input class="btn btn-warn pull-left" name="enable" type="submit" value="<%= t('Enable') %>" />
|
23
|
+
</form>
|
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
|
+
</form>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
</header>
|
31
|
+
|
32
|
+
<table class="table table-bordered table-striped">
|
33
|
+
<tbody>
|
34
|
+
<tr>
|
35
|
+
<th><%= t 'Status' %></th>
|
36
|
+
<td><%= @job.status %></td>
|
37
|
+
</tr>
|
38
|
+
<tr>
|
39
|
+
<th><%= t 'Name' %></th>
|
40
|
+
<td><%= @job.name %></td>
|
41
|
+
</tr>
|
42
|
+
<tr>
|
43
|
+
<th><%= t 'Namespace' %></th>
|
44
|
+
<td><%= @job.namespace %></td>
|
45
|
+
</tr>
|
46
|
+
<tr>
|
47
|
+
<th><%= t 'Description' %></th>
|
48
|
+
<td><%= @job.description %></td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<th><%= t 'Message' %></th>
|
52
|
+
<td><pre><%= @job.pretty_message %></pre></td>
|
53
|
+
</tr>
|
54
|
+
<tr>
|
55
|
+
<th><%= t 'Cron' %></th>
|
56
|
+
<td><%= @job.cron.gsub(" ", " ") %></td>
|
57
|
+
</tr>
|
58
|
+
<tr>
|
59
|
+
<th><%= t 'Last enqueued' %></th>
|
60
|
+
<td><%= @job.last_enqueue_time ? relative_time(@job.last_enqueue_time) : "-" %></td>
|
61
|
+
</tr>
|
62
|
+
</tbody>
|
63
|
+
</table>
|
64
|
+
|
65
|
+
<header class="row">
|
66
|
+
<div class="col-sm-12">
|
67
|
+
<h4>
|
68
|
+
<%= t 'History' %>
|
69
|
+
</h4>
|
70
|
+
</div>
|
71
|
+
</header>
|
72
|
+
|
73
|
+
<% if @job.jid_history_from_redis.size > 0 %>
|
74
|
+
<table class="table table-hover table-bordered table-striped">
|
75
|
+
<thead>
|
76
|
+
<tr>
|
77
|
+
<th><%= t 'Enqueued' %></th>
|
78
|
+
<th><%= t 'JID' %></th>
|
79
|
+
</tr>
|
80
|
+
</thead>
|
81
|
+
<tbody>
|
82
|
+
<% @job.jid_history_from_redis.each do |jid_history| %>
|
83
|
+
<tr>
|
84
|
+
<td><%= jid_history['enqueued'] %></td>
|
85
|
+
<td><%= jid_history['jid'] %></td>
|
86
|
+
</tr>
|
87
|
+
<% end %>
|
88
|
+
</tbody>
|
89
|
+
</table>
|
90
|
+
<% else %>
|
91
|
+
<div class='alert alert-success'><%= t 'NoHistoryWereFound' %></div>
|
92
|
+
<% end %>
|
data/lib/sidekiq/cron/web.rb
CHANGED
@@ -3,7 +3,16 @@ require "sidekiq/cron/job"
|
|
3
3
|
require "sidekiq/cron/namespace"
|
4
4
|
|
5
5
|
if defined?(Sidekiq::Web)
|
6
|
-
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('
|
6
|
+
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('8.0.0')
|
7
|
+
Sidekiq::Web.configure do |config|
|
8
|
+
config.register(
|
9
|
+
Sidekiq::Cron::WebExtension, # Class which contains the HTTP actions, required
|
10
|
+
name: "cron", # the name of the extension, used to namespace assets
|
11
|
+
tab: "Cron", # labels(s) of the UI tabs
|
12
|
+
index: "cron", # index route(s) for each tab
|
13
|
+
)
|
14
|
+
end
|
15
|
+
elsif Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.3.0')
|
7
16
|
Sidekiq::Web.register(
|
8
17
|
Sidekiq::Cron::WebExtension, # Class which contains the HTTP actions, required
|
9
18
|
name: "cron", # the name of the extension, used to namespace assets
|
@@ -1,25 +1,46 @@
|
|
1
1
|
module Sidekiq
|
2
2
|
module Cron
|
3
3
|
module WebExtension
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"#{root_path}cron/namespaces/#{route_params[:namespace]}"
|
4
|
+
module Helpers
|
5
|
+
def cron_route_params(key)
|
6
|
+
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
|
7
|
+
route_params(key)
|
8
|
+
else
|
9
|
+
route_params[key]
|
11
10
|
end
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# This method constructs the URL for the cron jobs page within the specified namespace.
|
14
|
+
def namespace_redirect_path
|
15
|
+
"#{root_path}cron/namespaces/#{cron_route_params(:namespace)}"
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
def redirect_to_previous_or_default
|
19
|
+
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
|
20
|
+
redirect url_params('redirect') || namespace_redirect_path
|
21
|
+
else
|
22
|
+
redirect params["redirect"] || namespace_redirect_path
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
26
|
+
def render_erb(view)
|
27
|
+
path = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0") ? "views" : "views/legacy"
|
28
|
+
views_path = File.join(File.expand_path("..", __FILE__), path)
|
29
|
+
erb(File.read(File.join(views_path, "#{view}.erb")))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.registered(app)
|
34
|
+
locales = if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
|
35
|
+
Sidekiq::Web.configure.locales
|
36
|
+
else
|
37
|
+
app.settings.locales
|
38
|
+
end
|
39
|
+
|
40
|
+
locales << File.join(File.expand_path("..", __FILE__), "locales")
|
41
|
+
|
42
|
+
app.helpers(Helpers)
|
43
|
+
|
23
44
|
# Index page.
|
24
45
|
app.get '/cron' do
|
25
46
|
@current_namespace = 'default'
|
@@ -30,7 +51,7 @@ module Sidekiq
|
|
30
51
|
|
31
52
|
# Detail page for a specific namespace.
|
32
53
|
app.get '/cron/namespaces/:name' do
|
33
|
-
@current_namespace =
|
54
|
+
@current_namespace = cron_route_params(:name)
|
34
55
|
@cron_jobs = Sidekiq::Cron::Job.all(@current_namespace)
|
35
56
|
|
36
57
|
render_erb(:cron)
|
@@ -38,8 +59,8 @@ module Sidekiq
|
|
38
59
|
|
39
60
|
# Display job detail + jid history.
|
40
61
|
app.get '/cron/namespaces/:namespace/jobs/:name' do
|
41
|
-
@current_namespace =
|
42
|
-
@job = Sidekiq::Cron::Job.find(
|
62
|
+
@current_namespace = cron_route_params(:namespace)
|
63
|
+
@job = Sidekiq::Cron::Job.find(cron_route_params(:name), @current_namespace)
|
43
64
|
|
44
65
|
if @job
|
45
66
|
render_erb(:cron_show)
|
@@ -50,14 +71,14 @@ module Sidekiq
|
|
50
71
|
|
51
72
|
# Enqueue all cron jobs.
|
52
73
|
app.post '/cron/namespaces/:namespace/all/enqueue' do
|
53
|
-
Sidekiq::Cron::Job.all(
|
74
|
+
Sidekiq::Cron::Job.all(cron_route_params(:namespace)).each(&:enqueue!)
|
54
75
|
|
55
76
|
redirect_to_previous_or_default
|
56
77
|
end
|
57
78
|
|
58
79
|
# Enqueue cron job.
|
59
80
|
app.post '/cron/namespaces/:namespace/jobs/:name/enqueue' do
|
60
|
-
if job = Sidekiq::Cron::Job.find(
|
81
|
+
if job = Sidekiq::Cron::Job.find(cron_route_params(:name), cron_route_params(:namespace))
|
61
82
|
job.enqueue!
|
62
83
|
end
|
63
84
|
|
@@ -66,14 +87,14 @@ module Sidekiq
|
|
66
87
|
|
67
88
|
# Delete all schedules.
|
68
89
|
app.post '/cron/namespaces/:namespace/all/delete' do
|
69
|
-
Sidekiq::Cron::Job.all(
|
90
|
+
Sidekiq::Cron::Job.all(cron_route_params(:namespace)).each(&:destroy)
|
70
91
|
|
71
92
|
redirect_to_previous_or_default
|
72
93
|
end
|
73
94
|
|
74
95
|
# Delete schedule.
|
75
96
|
app.post '/cron/namespaces/:namespace/jobs/:name/delete' do
|
76
|
-
if job = Sidekiq::Cron::Job.find(
|
97
|
+
if job = Sidekiq::Cron::Job.find(cron_route_params(:name), cron_route_params(:namespace))
|
77
98
|
job.destroy
|
78
99
|
end
|
79
100
|
|
@@ -82,14 +103,14 @@ module Sidekiq
|
|
82
103
|
|
83
104
|
# Enable all jobs.
|
84
105
|
app.post '/cron/namespaces/:namespace/all/enable' do
|
85
|
-
Sidekiq::Cron::Job.all(
|
106
|
+
Sidekiq::Cron::Job.all(cron_route_params(:namespace)).each(&:enable!)
|
86
107
|
|
87
108
|
redirect_to_previous_or_default
|
88
109
|
end
|
89
110
|
|
90
111
|
# Enable job.
|
91
112
|
app.post '/cron/namespaces/:namespace/jobs/:name/enable' do
|
92
|
-
if job = Sidekiq::Cron::Job.find(
|
113
|
+
if job = Sidekiq::Cron::Job.find(cron_route_params(:name), cron_route_params(:namespace))
|
93
114
|
job.enable!
|
94
115
|
end
|
95
116
|
|
@@ -98,14 +119,14 @@ module Sidekiq
|
|
98
119
|
|
99
120
|
# Disable all jobs.
|
100
121
|
app.post '/cron/namespaces/:namespace/all/disable' do
|
101
|
-
Sidekiq::Cron::Job.all(
|
122
|
+
Sidekiq::Cron::Job.all(cron_route_params(:namespace)).each(&:disable!)
|
102
123
|
|
103
124
|
redirect_to_previous_or_default
|
104
125
|
end
|
105
126
|
|
106
127
|
# Disable job.
|
107
128
|
app.post '/cron/namespaces/:namespace/jobs/:name/disable' do
|
108
|
-
if job = Sidekiq::Cron::Job.find(
|
129
|
+
if job = Sidekiq::Cron::Job.find(cron_route_params(:name), cron_route_params(:namespace))
|
109
130
|
job.disable!
|
110
131
|
end
|
111
132
|
|
data/lib/sidekiq/cron.rb
CHANGED
@@ -28,6 +28,17 @@ module Sidekiq
|
|
28
28
|
# The default namespace is used when no namespace is specified.
|
29
29
|
attr_accessor :default_namespace
|
30
30
|
|
31
|
+
# List of available namespaces
|
32
|
+
#
|
33
|
+
# If not set, Sidekiq Cron will dynamically fetch available namespaces
|
34
|
+
# by retrieving existing jobs from Redis.
|
35
|
+
#
|
36
|
+
# This dynamic fetching can negatively impact performance in certain cases.
|
37
|
+
# To mitigate this, you can provide the list of namespaces explicitly.
|
38
|
+
# If a job specifies a namespace that is not included in the provided list,
|
39
|
+
# a warning will be logged, and the job will be assigned to the default namespace.
|
40
|
+
attr_accessor :available_namespaces
|
41
|
+
|
31
42
|
# The parsing mode when using the natural language cron syntax from the `fugit` gem.
|
32
43
|
#
|
33
44
|
# :single -- use the first parsed cron line and ignore the rest (default)
|
@@ -42,25 +53,14 @@ module Sidekiq
|
|
42
53
|
# jobs that missed their schedules during the deployment. E.g., jobs that run once a day.
|
43
54
|
attr_accessor :reschedule_grace_period
|
44
55
|
|
45
|
-
# List of available namespaces
|
46
|
-
#
|
47
|
-
# If not set, Sidekiq Cron will dynamically fetch available namespaces
|
48
|
-
# by retrieving existing jobs from Redis.
|
49
|
-
#
|
50
|
-
# This dynamic fetching can negatively impact performance in certain cases.
|
51
|
-
# To mitigate this, you can provide the list of namespaces explicitly.
|
52
|
-
# If a job specifies a namespace that is not included in the provided list,
|
53
|
-
# a warning will be logged, and the job will be assigned to the default namespace.
|
54
|
-
attr_accessor :available_namespaces
|
55
|
-
|
56
56
|
def initialize
|
57
57
|
@cron_poll_interval = 30
|
58
58
|
@cron_schedule_file = 'config/schedule.yml'
|
59
59
|
@cron_history_size = 10
|
60
60
|
@default_namespace = 'default'
|
61
|
+
@available_namespaces = [@default_namespace]
|
61
62
|
@natural_cron_parsing_mode = :single
|
62
63
|
@reschedule_grace_period = 60
|
63
|
-
@available_namespaces = nil
|
64
64
|
end
|
65
65
|
|
66
66
|
def natural_cron_parsing_mode=(mode)
|
data/sidekiq-cron.gemspec
CHANGED
@@ -33,8 +33,8 @@ Gem::Specification.new do |s|
|
|
33
33
|
|
34
34
|
s.add_development_dependency("minitest", "~> 5.15")
|
35
35
|
s.add_development_dependency("mocha", "~> 2.1")
|
36
|
-
s.add_development_dependency("rack", "
|
37
|
-
s.add_development_dependency("rack-test", "
|
36
|
+
s.add_development_dependency("rack", ">= 2.2")
|
37
|
+
s.add_development_dependency("rack-test", ">= 1.1")
|
38
38
|
s.add_development_dependency("rake", "~> 13.0")
|
39
39
|
s.add_development_dependency("simplecov", "~> 0.21")
|
40
40
|
s.add_development_dependency("simplecov-cobertura", "~> 2.1")
|