resque-stages 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +103 -0
- data/.rubocop_todo.yml +34 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +172 -0
- data/LICENSE.txt +21 -0
- data/README.md +250 -0
- data/Rakefile +8 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/lib/resque-stages.rb +11 -0
- data/lib/resque/plugins/stages.rb +110 -0
- data/lib/resque/plugins/stages/cleaner.rb +36 -0
- data/lib/resque/plugins/stages/redis_access.rb +16 -0
- data/lib/resque/plugins/stages/staged_group.rb +181 -0
- data/lib/resque/plugins/stages/staged_group_list.rb +79 -0
- data/lib/resque/plugins/stages/staged_group_stage.rb +275 -0
- data/lib/resque/plugins/stages/staged_job.rb +271 -0
- data/lib/resque/plugins/stages/version.rb +9 -0
- data/lib/resque/server/public/stages.css +56 -0
- data/lib/resque/server/views/_group_stages_list_pagination.erb +67 -0
- data/lib/resque/server/views/_group_stages_list_table.erb +25 -0
- data/lib/resque/server/views/_stage_job_list_pagination.erb +72 -0
- data/lib/resque/server/views/_stage_job_list_table.erb +46 -0
- data/lib/resque/server/views/_staged_group_list_pagination.erb +67 -0
- data/lib/resque/server/views/_staged_group_list_table.erb +44 -0
- data/lib/resque/server/views/group_stages_list.erb +58 -0
- data/lib/resque/server/views/groups.erb +40 -0
- data/lib/resque/server/views/job_details.erb +91 -0
- data/lib/resque/server/views/stage.erb +64 -0
- data/lib/resque/stages_server.rb +240 -0
- data/read_me/groups_list.png +0 -0
- data/read_me/job.png +0 -0
- data/read_me/stage.png +0 -0
- data/read_me/stages.png +0 -0
- data/resque-stages.gemspec +49 -0
- data/spec/rails_helper.rb +40 -0
- data/spec/resque/plugins/stages/cleaner_spec.rb +82 -0
- data/spec/resque/plugins/stages/staged_group_list_spec.rb +96 -0
- data/spec/resque/plugins/stages/staged_group_spec.rb +226 -0
- data/spec/resque/plugins/stages/staged_group_stage_spec.rb +293 -0
- data/spec/resque/plugins/stages/staged_job_spec.rb +324 -0
- data/spec/resque/plugins/stages_spec.rb +369 -0
- data/spec/resque/server/public/stages.css_spec.rb +18 -0
- data/spec/resque/server/views/group_stages_list.erb_spec.rb +67 -0
- data/spec/resque/server/views/groups.erb_spec.rb +81 -0
- data/spec/resque/server/views/job_details.erb_spec.rb +100 -0
- data/spec/resque/server/views/stage.erb_spec.rb +68 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/01_utils/fake_logger.rb +7 -0
- data/spec/support/config/redis-auth.yml +12 -0
- data/spec/support/fake_logger.rb +7 -0
- data/spec/support/jobs/basic_job.rb +17 -0
- data/spec/support/jobs/compressed_job.rb +18 -0
- data/spec/support/jobs/retry_job.rb +21 -0
- data/spec/support/purge_all.rb +15 -0
- metadata +297 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
<div class="table_container">
|
2
|
+
<table>
|
3
|
+
<tr>
|
4
|
+
<th><a href="<%= u("stages/stage") %>?<%=
|
5
|
+
{ group_stage_id: group_stage_id,
|
6
|
+
sort: "class_name",
|
7
|
+
page_size: page_size,
|
8
|
+
page_num: page_num,
|
9
|
+
order: staged_group_stage.order_param("class_name", sort_by, sort_order) }.to_param %>">
|
10
|
+
Class
|
11
|
+
</a></th>
|
12
|
+
<th><a href="<%= u("stages/stage") %>?<%=
|
13
|
+
{ group_stage_id: group_stage_id,
|
14
|
+
sort: "status",
|
15
|
+
page_size: page_size,
|
16
|
+
page_num: page_num,
|
17
|
+
order: staged_group_stage.order_param("status", sort_by, sort_order) }.to_param %>">
|
18
|
+
Status
|
19
|
+
</a></th>
|
20
|
+
<th><a href="<%= u("stages/stage") %>?<%=
|
21
|
+
{ group_stage_id: group_stage_id,
|
22
|
+
sort: "status_message",
|
23
|
+
page_size: page_size,
|
24
|
+
page_num: page_num,
|
25
|
+
order: staged_group_stage.order_param("status_message", sort_by, sort_order) }.to_param %>">
|
26
|
+
Message
|
27
|
+
</a></th>
|
28
|
+
<th>Args</th>
|
29
|
+
</tr>
|
30
|
+
|
31
|
+
<% jobs.each do |job| %>
|
32
|
+
<tr>
|
33
|
+
<td>
|
34
|
+
<a href="<%= u("stages") %>/job_details?<%= { job_id: job.job_id }.to_param %>">
|
35
|
+
<%= job.class_name %>
|
36
|
+
</a>
|
37
|
+
</td>
|
38
|
+
<td><%= job.status %></td>
|
39
|
+
<td><%= job.status_message %></td>
|
40
|
+
<td>
|
41
|
+
<pre><code><%= "".html_safe + job.uncompressed_args.to_yaml %></code></pre>
|
42
|
+
</td>
|
43
|
+
</tr>
|
44
|
+
<% end %>
|
45
|
+
</table>
|
46
|
+
</div>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<div class="stages_pagination_block">
|
2
|
+
<% total_pages = staged_group_list.num_groups / page_size %>
|
3
|
+
<% total_pages += 1 if staged_group_list.num_groups % page_size > 0 %>
|
4
|
+
<% page_num = 1 if page_num > total_pages || page_num < 1 %>
|
5
|
+
<% first_page = [1, page_num - 3].max %>
|
6
|
+
<% last_page = [total_pages, page_num + 3].min %>
|
7
|
+
<% last_page = page_num < 4 ? [total_pages, last_page + (4 - page_num)].min : last_page %>
|
8
|
+
<% first_page = page_num > total_pages - 3 ? [1, first_page + ((total_pages - page_num) - 3)].max : first_page %>
|
9
|
+
|
10
|
+
<% if total_pages > 1 %>
|
11
|
+
<div class="stages_prev_links">
|
12
|
+
<a href="<%= u("stages") %>?<%= { sort: @sort_by,
|
13
|
+
page_size: page_size,
|
14
|
+
page_num: 1,
|
15
|
+
order: @sort_order }.to_param %>"
|
16
|
+
class="stages_first_page"
|
17
|
+
disabled="<%= first_page > 1 %>">
|
18
|
+
<< First
|
19
|
+
</a>
|
20
|
+
|
21
|
+
<a href="<%= u("stages") %>?<%= { sort: @sort_by,
|
22
|
+
page_size: page_size,
|
23
|
+
page_num: [1, page_num - 1].max,
|
24
|
+
order: @sort_order }.to_param %>"
|
25
|
+
class="stages_prev_page"
|
26
|
+
disabled="<%= page_num > 1 %>">
|
27
|
+
< Prev
|
28
|
+
</a>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="stages_pages">
|
32
|
+
<% (first_page..last_page).each do |page_number| %>
|
33
|
+
<% if page_number != page_num %>
|
34
|
+
<a href="<%= u("stages") %>?<%= { sort: @sort_by,
|
35
|
+
page_size: page_size,
|
36
|
+
page_num: page_number,
|
37
|
+
order: @sort_order }.to_param %>"
|
38
|
+
class="stages_page">
|
39
|
+
<%= page_number %>
|
40
|
+
</a>
|
41
|
+
<% else %>
|
42
|
+
<%= page_number %>
|
43
|
+
<% end %>
|
44
|
+
<% end %>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<div class="stages_next_links">
|
48
|
+
<a href="<%= u("stages") %>?<%= { sort: @sort_by,
|
49
|
+
page_size: page_size,
|
50
|
+
page_num: [total_pages, page_num + 1].min,
|
51
|
+
order: @sort_order }.to_param %>"
|
52
|
+
class="stages_next_page"
|
53
|
+
disabled="<%= page_num < last_page %>">
|
54
|
+
Next >
|
55
|
+
</a>
|
56
|
+
|
57
|
+
<a href="<%= u("stages") %>?<%= { sort: @sort_by,
|
58
|
+
page_size: page_size,
|
59
|
+
page_num: total_pages,
|
60
|
+
order: @sort_order }.to_param %>"
|
61
|
+
class="stages_last_page"
|
62
|
+
disabled="<%= last_page < total_pages %>">
|
63
|
+
Last >>
|
64
|
+
</a>
|
65
|
+
</div>
|
66
|
+
<% end %>
|
67
|
+
</div>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<div class="table_container">
|
2
|
+
<table>
|
3
|
+
<tr>
|
4
|
+
<th><a href="<%= u("stages") %>?<%=
|
5
|
+
{ sort: "description",
|
6
|
+
page_size: page_size,
|
7
|
+
page_num: page_num,
|
8
|
+
order: staged_group_list.order_param("description", sort_by, sort_order) }.to_param %>">
|
9
|
+
Description
|
10
|
+
</a></th>
|
11
|
+
<th><a href="<%= u("stages") %>?<%=
|
12
|
+
{ sort: "num_stages",
|
13
|
+
page_size: page_size,
|
14
|
+
page_num: page_num,
|
15
|
+
order: staged_group_list.order_param("num_stages", sort_by, sort_order) }.to_param %>">
|
16
|
+
Num Stages
|
17
|
+
</a></th>
|
18
|
+
<th><a href="<%= u("stages") %>?<%=
|
19
|
+
{ sort: "created_at",
|
20
|
+
page_size: page_size,
|
21
|
+
page_num: page_num,
|
22
|
+
order: staged_group_list.order_param("created_at", sort_by, sort_order) }.to_param %>">
|
23
|
+
Created
|
24
|
+
</a></th>
|
25
|
+
</tr>
|
26
|
+
|
27
|
+
<% groups.each do |group| %>
|
28
|
+
<tr>
|
29
|
+
<td>
|
30
|
+
<a href="<%= u("stages") %>/group_stages_list?<%= { group_id: group.group_id }.to_param %>">
|
31
|
+
<%= group.description.presence || " ".html_safe %>
|
32
|
+
</a>
|
33
|
+
</td>
|
34
|
+
<td>
|
35
|
+
<%= group.num_stages.to_i %>
|
36
|
+
</td>
|
37
|
+
<td>
|
38
|
+
<%= time_ago_in_words(group.created_at) %> ago
|
39
|
+
(<%= group.created_at %>)
|
40
|
+
</td>
|
41
|
+
</tr>
|
42
|
+
<% end %>
|
43
|
+
</table>
|
44
|
+
</div>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<link href="<%= u("stages/public/stages.css") %>" media="screen" rel="stylesheet" type="text/css">
|
2
|
+
|
3
|
+
<% group = Resque::Plugins::Stages::StagedGroup.new(@group_id) %>
|
4
|
+
|
5
|
+
<h1>
|
6
|
+
<%= group.description %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<a href="<%= u("stages") %>">
|
11
|
+
Groups
|
12
|
+
</a>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<p>
|
16
|
+
Num stages in this group = <%= group.num_stages %>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<% if group.num_stages > 0 %>
|
20
|
+
<h1>Stages</h1>
|
21
|
+
|
22
|
+
<% stages = group.paged_stages(@page_num, @page_size) %>
|
23
|
+
|
24
|
+
<div class="stages_reset"/>
|
25
|
+
|
26
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_group_stages_list_pagination.erb")),
|
27
|
+
locals: { group: group,
|
28
|
+
group_id: @group_id,
|
29
|
+
page_num: @page_num,
|
30
|
+
page_size: @page_size }) %>
|
31
|
+
|
32
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_group_stages_list_table.erb")),
|
33
|
+
locals: { stages: stages, show_class: false }) %>
|
34
|
+
|
35
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_group_stages_list_pagination.erb")),
|
36
|
+
locals: { group: group,
|
37
|
+
group_id: @group_id,
|
38
|
+
page_num: @page_num,
|
39
|
+
page_size: @page_size }) %>
|
40
|
+
|
41
|
+
<br/>
|
42
|
+
<% end %>
|
43
|
+
|
44
|
+
<form method="POST" action="<%= u("stages/initiate_group") %>?<%=
|
45
|
+
{ group_id: group.group_id }.to_param %>">
|
46
|
+
<input type="submit" name="" value="Initiate Group"/>
|
47
|
+
</form>
|
48
|
+
<form method="POST" action="<%= u("stages/delete_group") %>?<%= { group_id: group.group_id }.to_param %>">
|
49
|
+
<input type="submit" name="" value="Delete"/>
|
50
|
+
</form>
|
51
|
+
|
52
|
+
<div class="stages_reset"/>
|
53
|
+
<br/>
|
54
|
+
<div>
|
55
|
+
<p>
|
56
|
+
Stages v<%= Resque::Plugins::Stages::VERSION %>
|
57
|
+
</p>
|
58
|
+
</div>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<link href="<%= u("stages/public/stages.css") %>" media="screen" rel="stylesheet" type="text/css">
|
2
|
+
|
3
|
+
<h1>Staged Groups</h1>
|
4
|
+
|
5
|
+
<% staged_group_list = Resque::Plugins::Stages::StagedGroupList.new %>
|
6
|
+
|
7
|
+
<div class="stages_reset"/>
|
8
|
+
|
9
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_staged_group_list_pagination.erb")),
|
10
|
+
locals: { staged_group_list: staged_group_list, page_num: @page_num, page_size: @page_size }) %>
|
11
|
+
|
12
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_staged_group_list_table.erb")),
|
13
|
+
locals: { groups: staged_group_list.paginated_groups(@sort_by, @sort_order, @page_num, @page_size),
|
14
|
+
staged_group_list: staged_group_list,
|
15
|
+
sort_by: @sort_by,
|
16
|
+
sort_order: @sort_order,
|
17
|
+
page_num: @page_num,
|
18
|
+
page_size: @page_size }) %>
|
19
|
+
|
20
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_staged_group_list_pagination.erb")),
|
21
|
+
locals: { staged_group_list: staged_group_list, page_num: @page_num, page_size: @page_size }) %>
|
22
|
+
|
23
|
+
<br/>
|
24
|
+
|
25
|
+
<div>
|
26
|
+
<form method="POST" action="<%= u("stages/delete_all_groups") %>">
|
27
|
+
<input type="submit" name="" value="Delete All Groups"/>
|
28
|
+
</form>
|
29
|
+
<form method="POST" action="<%= u("stages/cleanup_jobs") %>">
|
30
|
+
<input type="submit" name="" value="Cleanup Jobs"/>
|
31
|
+
</form>
|
32
|
+
<form method="POST" action="<%= u("stages/purge_all") %>">
|
33
|
+
<input type="submit" name="" value="Purge"/>
|
34
|
+
</form>
|
35
|
+
</div>
|
36
|
+
<div class="stages_reset"/>
|
37
|
+
<br/>
|
38
|
+
<div>
|
39
|
+
Stages v<%= Resque::Plugins::Stages::VERSION %>
|
40
|
+
</div>
|
@@ -0,0 +1,91 @@
|
|
1
|
+
<link href="<%= u("stages/public/stages.css") %>" media="screen" rel="stylesheet" type="text/css">
|
2
|
+
|
3
|
+
<% job_details = Resque::Plugins::Stages::StagedJob.new(@job_id) %>
|
4
|
+
|
5
|
+
<h1>
|
6
|
+
<%= job_details.class_name %>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
<p>
|
10
|
+
<a href="<%= u("stages") %>">
|
11
|
+
Groups
|
12
|
+
</a>
|
13
|
+
|
|
14
|
+
<% if job_details.staged_group_stage&.staged_group %>
|
15
|
+
<a href="<%= u("stages/group_stages_list") %>?<%= { group_id: job_details.staged_group_stage.staged_group.group_id }.to_param %>">
|
16
|
+
<%= job_details.staged_group_stage.staged_group&.description %>
|
17
|
+
</a>
|
18
|
+
<% end %>
|
19
|
+
|
|
20
|
+
<% if job_details.staged_group_stage %>
|
21
|
+
<a href="<%= u("stages/stage") %>?<%= { group_stage_id: job_details.staged_group_stage.group_stage_id }.to_param %>">
|
22
|
+
<%= job_details.staged_group_stage.number %>
|
23
|
+
</a>
|
24
|
+
<% end %>
|
25
|
+
</p>
|
26
|
+
|
27
|
+
<div class="table_container">
|
28
|
+
<table>
|
29
|
+
<tr>
|
30
|
+
<td>
|
31
|
+
Enqueued
|
32
|
+
</td>
|
33
|
+
<td>
|
34
|
+
<%= time_ago_in_words(job_details.queue_time) %> ago
|
35
|
+
(<%= job_details.queue_time %>)
|
36
|
+
</td>
|
37
|
+
</tr>
|
38
|
+
<tr>
|
39
|
+
<td>
|
40
|
+
Status
|
41
|
+
</td>
|
42
|
+
<td>
|
43
|
+
<%= job_details.status %>
|
44
|
+
</td>
|
45
|
+
</tr>
|
46
|
+
<tr>
|
47
|
+
<td>
|
48
|
+
Class
|
49
|
+
</td>
|
50
|
+
<td>
|
51
|
+
<%= job_details.class_name %>
|
52
|
+
</td>
|
53
|
+
</tr>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>
|
57
|
+
Params
|
58
|
+
</td>
|
59
|
+
<td>
|
60
|
+
<pre><code><%= "".html_safe + job_details.uncompressed_args.to_yaml %></code></pre>
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td>
|
65
|
+
Message
|
66
|
+
</td>
|
67
|
+
<td>
|
68
|
+
<%= job_details.status_message %>
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
|
74
|
+
<br/>
|
75
|
+
|
76
|
+
<% if job_details.pending? %>
|
77
|
+
<form method="POST" action="<%= u("stages/queue_job") %>?<%= { job_id: @job_id }.to_param %>">
|
78
|
+
<input type="submit" name="" value="Queue Job"/>
|
79
|
+
</form>
|
80
|
+
<% end %>
|
81
|
+
|
82
|
+
<form method="POST" action="<%= u("stages/delete_job") %>?<%= { job_id: @job_id }.to_param %>">
|
83
|
+
<input type="submit" name="" value="Delete Job"/>
|
84
|
+
</form>
|
85
|
+
|
86
|
+
<div class="stages_reset"/>
|
87
|
+
|
88
|
+
<br/>
|
89
|
+
<div>
|
90
|
+
Stages v<%= Resque::Plugins::Stages::VERSION %>
|
91
|
+
</div>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<link href="<%= u("stages/public/stages.css") %>" media="screen" rel="stylesheet" type="text/css">
|
2
|
+
|
3
|
+
<% staged_group_stage = Resque::Plugins::Stages::StagedGroupStage.new(params[:group_stage_id]) %>
|
4
|
+
|
5
|
+
<h1>Stage <%= staged_group_stage.number %></h1>
|
6
|
+
|
7
|
+
<p>
|
8
|
+
<a href="<%= u("stages") %>">
|
9
|
+
Groups
|
10
|
+
</a>
|
11
|
+
|
|
12
|
+
<% if staged_group_stage.staged_group %>
|
13
|
+
<a href="<%= u("stages/group_stages_list") %>?<%= { group_id: staged_group_stage.staged_group.group_id }.to_param %>">
|
14
|
+
<%= staged_group_stage.staged_group&.description %>
|
15
|
+
</a>
|
16
|
+
<% end %>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<div class="table_container">
|
20
|
+
<table>
|
21
|
+
<tr>
|
22
|
+
<td>Num jobs</td>
|
23
|
+
<td><%= staged_group_stage.num_jobs %></td>
|
24
|
+
</tr>
|
25
|
+
<tr>
|
26
|
+
<td>Status</td>
|
27
|
+
<td><%= staged_group_stage.status %></td>
|
28
|
+
</tr>
|
29
|
+
</table>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div class="stages_reset"/>
|
33
|
+
|
34
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_stage_job_list_pagination.erb")),
|
35
|
+
locals: { staged_group_stage: staged_group_stage, page_num: @page_num, page_size: @page_size }) %>
|
36
|
+
|
37
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_stage_job_list_table.erb")),
|
38
|
+
locals: { jobs: staged_group_stage.paginated_jobs(@sort_by, @sort_order, @page_num, @page_size),
|
39
|
+
staged_group_stage: staged_group_stage,
|
40
|
+
group_stage_id: params[:group_stage_id],
|
41
|
+
sort_by: @sort_by,
|
42
|
+
sort_order: @sort_order,
|
43
|
+
page_num: @page_num,
|
44
|
+
page_size: @page_size }) %>
|
45
|
+
|
46
|
+
<%= erb(File.read(Resque::StagesServer.erb_path("_stage_job_list_pagination.erb")),
|
47
|
+
locals: { staged_group_stage: staged_group_stage, page_num: @page_num, page_size: @page_size }) %>
|
48
|
+
|
49
|
+
<br/>
|
50
|
+
|
51
|
+
<div>
|
52
|
+
<form method="POST" action="<%= u("stages/initiate_stage") %>?<%= { group_stage_id: staged_group_stage.group_stage_id }.to_param %>">
|
53
|
+
<input type="submit" name="" value="Initiate"/>
|
54
|
+
</form>
|
55
|
+
<form method="POST" action="<%= u("stages/delete_stage") %>?<%= { group_stage_id: staged_group_stage.group_stage_id }.to_param %>">
|
56
|
+
<input type="submit" name="" value="Delete"/>
|
57
|
+
</form>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div class="stages_reset"/>
|
61
|
+
<br/>
|
62
|
+
<div>
|
63
|
+
Stages v<%= Resque::Plugins::Stages::VERSION %>
|
64
|
+
</div>
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "resque"
|
4
|
+
require "resque/server"
|
5
|
+
require "resque-stages"
|
6
|
+
require "action_view/helpers/output_safety_helper"
|
7
|
+
require "action_view/helpers/capture_helper"
|
8
|
+
require "action_view/helpers/date_helper"
|
9
|
+
|
10
|
+
# rubocop:disable Metrics/ModuleLength
|
11
|
+
|
12
|
+
module Resque
|
13
|
+
# Extends Resque Web Based UI.
|
14
|
+
# Structure has been borrowed from ResqueHistory.
|
15
|
+
module StagesServer
|
16
|
+
include ActionView::Helpers::DateHelper
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def erb_path(filename)
|
20
|
+
File.join(File.dirname(__FILE__), "server", "views", filename)
|
21
|
+
end
|
22
|
+
|
23
|
+
def public_path(filename)
|
24
|
+
File.join(File.dirname(__FILE__), "server", "public", filename)
|
25
|
+
end
|
26
|
+
|
27
|
+
def included(base)
|
28
|
+
add_page_views(base)
|
29
|
+
add_button_callbacks(base)
|
30
|
+
add_static_files(base)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def add_page_views(base)
|
36
|
+
groups_list(base)
|
37
|
+
group_stages_list(base)
|
38
|
+
stage_jobs_list(base)
|
39
|
+
job_details(base)
|
40
|
+
end
|
41
|
+
|
42
|
+
def groups_list(base)
|
43
|
+
stages_key_params(base)
|
44
|
+
|
45
|
+
base.class_eval do
|
46
|
+
get "/stages" do
|
47
|
+
set_stages_key_params
|
48
|
+
|
49
|
+
erb File.read(Resque::StagesServer.erb_path("groups.erb"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def stages_key_params(base)
|
55
|
+
base.class_eval do
|
56
|
+
def set_stages_key_params
|
57
|
+
@sort_by = params[:sort] || "description"
|
58
|
+
@sort_order = params[:order] || "asc"
|
59
|
+
@page_num = (params[:page_num] || 1).to_i
|
60
|
+
@page_size = (params[:page_size] || 20).to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def group_stages_list(base)
|
66
|
+
group_stages_list_params(base)
|
67
|
+
|
68
|
+
base.class_eval do
|
69
|
+
get "/stages/group_stages_list" do
|
70
|
+
set_group_stages_list_params_params
|
71
|
+
|
72
|
+
erb File.read(Resque::StagesServer.erb_path("group_stages_list.erb"))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def group_stages_list_params(base)
|
78
|
+
base.class_eval do
|
79
|
+
def set_group_stages_list_params_params
|
80
|
+
@group_id = params[:group_id]
|
81
|
+
@page_num = (params[:page_num] || 1).to_i
|
82
|
+
@page_size = (params[:page_size] || 20).to_i
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def stage_jobs_list(base)
|
88
|
+
stage_jobs_key_params(base)
|
89
|
+
|
90
|
+
base.class_eval do
|
91
|
+
get "/stages/stage" do
|
92
|
+
set_stage_jobs_key_params
|
93
|
+
|
94
|
+
erb File.read(Resque::StagesServer.erb_path("stage.erb"))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def stage_jobs_key_params(base)
|
100
|
+
base.class_eval do
|
101
|
+
def set_stage_jobs_key_params
|
102
|
+
@group_stage_id = params[:group_stage_id]
|
103
|
+
@sort_by = params[:sort] || "status"
|
104
|
+
@sort_order = params[:order] || "desc"
|
105
|
+
@page_num = (params[:page_num] || 1).to_i
|
106
|
+
@page_size = (params[:page_size] || 20).to_i
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def job_details(base)
|
112
|
+
base.class_eval do
|
113
|
+
get "/stages/job_details" do
|
114
|
+
@job_id = params[:job_id]
|
115
|
+
|
116
|
+
erb File.read(Resque::StagesServer.erb_path("job_details.erb"))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_static_files(base)
|
122
|
+
base.class_eval do
|
123
|
+
get %r{/stages/public/([a-z_]+\.[a-z]+)} do
|
124
|
+
send_file Resque::StagesServer.public_path(params[:captures]&.first)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def add_button_callbacks(base)
|
130
|
+
purge_all(base)
|
131
|
+
cleanup_jobs(base)
|
132
|
+
delete_all_groups(base)
|
133
|
+
initiate_group(base)
|
134
|
+
delete_group(base)
|
135
|
+
initiate_stage(base)
|
136
|
+
delete_stage(base)
|
137
|
+
queue_job(base)
|
138
|
+
delete_job(base)
|
139
|
+
end
|
140
|
+
|
141
|
+
def purge_all(base)
|
142
|
+
base.class_eval do
|
143
|
+
post "/stages/purge_all" do
|
144
|
+
Resque::Plugins::Stages::Cleaner.purge_all
|
145
|
+
|
146
|
+
redirect u("stages")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def cleanup_jobs(base)
|
152
|
+
base.class_eval do
|
153
|
+
post "/stages/cleanup_jobs" do
|
154
|
+
Resque::Plugins::Stages::Cleaner.cleanup_jobs
|
155
|
+
|
156
|
+
redirect u("stages")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def delete_all_groups(base)
|
162
|
+
base.class_eval do
|
163
|
+
post "/stages/delete_all_groups" do
|
164
|
+
Resque::Plugins::Stages::StagedGroupList.new.delete_all
|
165
|
+
|
166
|
+
redirect u("stages")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def initiate_group(base)
|
172
|
+
base.class_eval do
|
173
|
+
post "/stages/initiate_group" do
|
174
|
+
Resque::Plugins::Stages::StagedGroup.new(params[:group_id]).initiate
|
175
|
+
|
176
|
+
redirect u("stages")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def delete_group(base)
|
182
|
+
base.class_eval do
|
183
|
+
post "/stages/delete_group" do
|
184
|
+
Resque::Plugins::Stages::StagedGroup.new(params[:group_id]).delete
|
185
|
+
|
186
|
+
redirect u("stages")
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def initiate_stage(base)
|
192
|
+
base.class_eval do
|
193
|
+
post "/stages/initiate_stage" do
|
194
|
+
Resque::Plugins::Stages::StagedGroupStage.new(params[:group_stage_id]).initiate
|
195
|
+
|
196
|
+
redirect u("stages")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def delete_stage(base)
|
202
|
+
base.class_eval do
|
203
|
+
post "/stages/delete_stage" do
|
204
|
+
Resque::Plugins::Stages::StagedGroupStage.new(params[:group_stage_id]).delete
|
205
|
+
|
206
|
+
redirect u("stages")
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def queue_job(base)
|
212
|
+
base.class_eval do
|
213
|
+
post "/stages/queue_job" do
|
214
|
+
Resque::Plugins::Stages::StagedJob.new(params[:job_id]).enqueue_job
|
215
|
+
|
216
|
+
redirect u("stages")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def delete_job(base)
|
222
|
+
base.class_eval do
|
223
|
+
post "/stages/delete_job" do
|
224
|
+
Resque::Plugins::Stages::StagedJob.new(params[:job_id]).delete
|
225
|
+
|
226
|
+
redirect u("stages")
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
Resque::Server.tabs << "Stages"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
Resque::Server.class_eval do
|
237
|
+
include Resque::StagesServer
|
238
|
+
end
|
239
|
+
|
240
|
+
# rubocop:enable Metrics/ModuleLength
|