aboutsummaryrefslogtreecommitdiff
path: root/app/views/shared/_jobs.html.erb
blob: a5072673cbf58ce3d1cd08530159ae6b6bb030c9 (plain)
1
2
3
4
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<div class="panel-group"
     id="jobs"
     role="tablist"
     aria-multiselectable="true">

  <% job_states = Que.job_states %>

  <% jobs.each do |job| %>
    <% job_state = job_states.find { |x| x[:id] == job.id } %>

    <div class="panel panel-default">
      <div class="panel-heading" role="tab" id="jobHeading<%= job.id %>">
        <h4 class="panel-title">
          <a role="button"
             data-toggle="collapse"
             data-parent="#accordion"
             title="Job id: <%= job.id %>"
             href="#job_<%= job.id %>"
             aria-expanded="true"
             aria-controls="job_<%= job.id %>"
          >
            Job:
            <%= job.job_class.constantize.try(:job_title, job) || job.job_class %>
            <span class="caret"></span>
          </a>
          <span class="pull-right">
            <% if job.finished_at %>
              <span title="<%= job.finished_at %>">
                Finished
                <%= distance_of_time_in_words_to_now(
                  job.run_at, include_seconds: true
                ) %> ago
              </span>
            <% elsif job.expired_at %>
              <span title="<%= job.expired_at %>">
                Canceled at
                <%= distance_of_time_in_words_to_now(
                  job.expired_at, include_seconds: true
                ) %> ago
              </span>
            <% else %>
              <% if job['error_count'] != 0 %>
                <%= job['error_count'] %> failures,
              <% end %>
              <% if job_state %>
                running for
              <% else %>
                running
                <% if job['error_count'] != 0 %>again<% end %>
                in
              <% end %>
              <%= distance_of_time_in_words_to_now(
                job.run_at, include_seconds: true
              ) %>
            <% end %>
          </span>
        </h4>
      </div>
      <div id="job_<%= job.id %>"
           class="panel-collapse collapse in"
           role="tabpanel"
           aria-labelledby="jobHeading<%= job.id %>"
      >
        <div class="panel-body">
          <div class="row">
            <% if job_state %>
              <div class="col-md-10">
                Running now
              </div>
              <div class="col-md-2">
                PID: <%= job_state[:ruby_pid] %>
              </div>
            <% elsif job.finished_at %>
              <div class="col-md-12">
                <% if job['error_count'] == 0 %>
                  Finished without any errors
                <% else %>
                  Finished after <%= pluralize(job['error_count'], 'error') %>.
                <% end %>

                <% if job.args.last == 'build' %>
                  <%# TODO: Generalise this somehow %>
                  <dl class="dl-horizontal">
                    <% @mini_environment.backend_data.each do |(key, value)| %>
                      <dt><%= key %></dt>
                      <dd><pre><%= value %></pre></dd>
                    <% end %>
                  </dl>
                <% end %>
              </div>
            <% else %>
              <div class="col-md-10">
                <pre><%= job.last_error_message %></pre>
                <pre><%= job.last_error_backtrace %></pre>
              </div>
              <div class="col-md-2">
                <%= form_with(url: retry_now_que_job_path(job.id)) do %>
                  <%= submit_tag(
                    'Retry now',
                    class: 'btn btn-primary btn-lg btn-block'
                  ) %>
                <% end %>
                <%= form_with(url: cancel_que_job_path(job.id)) do %>
                  <%= submit_tag(
                    'Cancel',
                    class: 'btn btn-warning btn-lg btn-block',
                    style: 'margin-top: 5px;'
                  ) %>
                <% end %>
              </div>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  <% end %>
</div>