diff options
author | Christopher Baines <mail@cbaines.net> | 2018-04-07 15:30:44 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2018-04-12 19:05:31 +0100 |
commit | 1f43c32aa4288f5aafafc426cfb955f84732d9e3 (patch) | |
tree | 691e37c60f99822e615662703a85b3c3e35a02e7 | |
parent | 0a87ae262287d516b2a2c7c8db07c7d4393d5fa8 (diff) | |
download | govuk-mini-environment-admin-1f43c32aa4288f5aafafc426cfb955f84732d9e3.tar govuk-mini-environment-admin-1f43c32aa4288f5aafafc426cfb955f84732d9e3.tar.gz |
Improve the handling of jobs
Move the display in to a partial and improve. Handle the finished and
enqueued jobs in a more consistent way.
-rw-r--r-- | app/controllers/mini_environments_controller.rb | 9 | ||||
-rw-r--r-- | app/jobs/govuk_guix/build_job.rb | 9 | ||||
-rw-r--r-- | app/jobs/mini_environment_job.rb | 22 | ||||
-rw-r--r-- | app/views/backends/terraform_libvirt/show.html.erb | 7 | ||||
-rw-r--r-- | app/views/mini_environments/show.html.erb | 57 | ||||
-rw-r--r-- | app/views/shared/_jobs.html.erb | 58 |
6 files changed, 110 insertions, 52 deletions
diff --git a/app/controllers/mini_environments_controller.rb b/app/controllers/mini_environments_controller.rb index 639ea0a..6f31e70 100644 --- a/app/controllers/mini_environments_controller.rb +++ b/app/controllers/mini_environments_controller.rb @@ -78,4 +78,13 @@ class MiniEnvironmentsController < ApplicationController render 'show' end + + def jobs + [ + MiniEnvironmentJob.jobs(@mini_environment.id), + GovukGuix::BuildJob.jobs(@mini_environment.id) + ].flatten + end + + helper_method :jobs end diff --git a/app/jobs/govuk_guix/build_job.rb b/app/jobs/govuk_guix/build_job.rb index eb3794e..04d1a34 100644 --- a/app/jobs/govuk_guix/build_job.rb +++ b/app/jobs/govuk_guix/build_job.rb @@ -72,4 +72,13 @@ class GovukGuix::BuildJob < GovukGuix::Job "--signon-user=#{signon_user_to_sexp(signon_user)}" end end + + def self.jobs(mini_environment_id) + QueJob + .where( + job_class: name + ).where( + "args->>0 = '#{mini_environment_id}'" + ).to_a + end end diff --git a/app/jobs/mini_environment_job.rb b/app/jobs/mini_environment_job.rb index 9635e02..90fbbd4 100644 --- a/app/jobs/mini_environment_job.rb +++ b/app/jobs/mini_environment_job.rb @@ -34,4 +34,26 @@ class MiniEnvironmentJob < Que::Job ) super end + + def self.jobs(mini_environment_id) + [ + QueJob + .where( + job_class: name + ).where( + "args->>0 = '#{mini_environment_id}'" + ).to_a, + FinishedTerraformJob + .where( + job_class: name, + model_id: mini_environment_id + ) + ].flatten.sort_by do |x| + if x.instance_of? QueJob + x.run_at + else # FinishedTerraformJob + x.created_at + end + end + end end diff --git a/app/views/backends/terraform_libvirt/show.html.erb b/app/views/backends/terraform_libvirt/show.html.erb index 5207e54..b151c8e 100644 --- a/app/views/backends/terraform_libvirt/show.html.erb +++ b/app/views/backends/terraform_libvirt/show.html.erb @@ -118,3 +118,10 @@ License along with the GOV.UK Mini Environment Admin. If not, see </tr> <% end %> </table> + +<h3>Jobs</h3> + +<%= render( + partial: 'shared/jobs', + locals: { jobs: Backends::DeployTerraformLibvirtJob.jobs(@backend.id) } +) %> diff --git a/app/views/mini_environments/show.html.erb b/app/views/mini_environments/show.html.erb index f55a2d8..d380aaf 100644 --- a/app/views/mini_environments/show.html.erb +++ b/app/views/mini_environments/show.html.erb @@ -59,56 +59,9 @@ License along with the GOV.UK Mini Environment Admin. If not, see </div> </div> -<h2>Finished jobs</h2> +<h2>Jobs</h2> -<% @mini_environment.finished_terraform_jobs.each do |job| %> - <%= job.job_class %> - <%= job.created_at %> -<% end %> - -<h2>Enqueued jobs</h2> - -<div class="panel-group" - id="accordion" - role="tablist" - aria-multiselectable="true"> - - <% @mini_environment.enqueued_terraform_jobs.each do |job| %> - - <div class="panel panel-default"> - <div class="panel-heading" role="tab" id="headingOne"> - <h4 class="panel-title"> - <a role="button" - data-toggle="collapse" - data-parent="#accordion" - href="#collapseOne" - aria-expanded="true" - aria-controls="collapseOne"> - <%= job['job_class'] %> - </a> - <span class="pull-right"> - Retrying next in <%= distance_of_time_in_words_to_now(job['run_at'], include_seconds: true) %> - </span> - </h4> - </div> - <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> - <div class="panel-body"> - This job has failed <%= job['error_count'] %> times. - - <div class="pull-right"> - <%= form_with(url: retry_now_que_job_path(job['job_id'])) do %> - <%= submit_tag('Retry now', class: 'btn btn-default') - %> - <% end %> - <%= form_with(url: cancel_que_job_path(job['job_id'])) do %> - <%= submit_tag('Cancel', class: 'btn btn-default') - %> - <% end %> - </div> - - <pre><%= job['last_error'] %></pre> - </div> - </div> - </div> - <% end %> -</div> +<%= render( + partial: 'shared/jobs', + locals: { jobs: jobs } +) %> diff --git a/app/views/shared/_jobs.html.erb b/app/views/shared/_jobs.html.erb new file mode 100644 index 0000000..e70e8ef --- /dev/null +++ b/app/views/shared/_jobs.html.erb @@ -0,0 +1,58 @@ + +<div class="panel-group" + id="accordion" + role="tablist" + aria-multiselectable="true"> + + <% jobs.each do |job| %> + + <div class="panel panel-default"> + <div class="panel-heading" role="tab" id="headingOne"> + <h4 class="panel-title"> + <a role="button" + data-toggle="collapse" + data-parent="#accordion" + href="#collapseOne" + aria-expanded="true" + aria-controls="collapseOne"> + <%= job.job_class %> + </a> + <span class="pull-right"> + <% if job.instance_of? FinishedTerraformJob %> + Job finished at <%= job.created_at %> + <% else %> + <%= job['error_count'] %> failures, retrying next in + <%= distance_of_time_in_words_to_now( + job.run_at, include_seconds: true + ) %> + <% end %> + </span> + </h4> + </div> + <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> + <div class="panel-body"> + <div class="row"> + <div class="col-md-10"> + <pre><%= job['last_error'] %></pre> + </div> + <div class="col-md-2"> + <%= form_with(url: retry_now_que_job_path(job['job_id'])) do %> + <%= submit_tag( + 'Retry now', + class: 'btn btn-primary btn-lg btn-block' + ) %> + <% end %> + <%= form_with(url: cancel_que_job_path(job['job_id'])) do %> + <%= submit_tag( + 'Cancel Job', + class: 'btn btn-warning btn-lg btn-block', + style: 'margin-top: 5px;' + ) %> + <% end %> + </div> + </div> + </div> + </div> + </div> + <% end %> +</div> |