mission_control-jobs 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f46c22e66d7fc57d1543dd2fa8863b8b7284019ea4eb47b879a06702c0d89b9
4
- data.tar.gz: b891c7389226107a06ce9c5e53b824b91bf3be55e1d3ffe49a2e6419887f5553
3
+ metadata.gz: 5cae6550d727f9f26c6b5c0f1259a03c7a3f802abe8eb025973fab559b8a8f73
4
+ data.tar.gz: 98a0bea82a4f3b9c3a3d338719f419508eef9ae05dbfc356314f142d053a4d11
5
5
  SHA512:
6
- metadata.gz: bfc58d081a8dacd1f1c680284a342d6d078f60992dafb0bc2ba5b90cf80e17fe86a240d2fdc5d987adb15231474542f2fe4a067db77884ce2fe523e598ba6b2a
7
- data.tar.gz: c8dcc5e285e09c4a1b9607633c82565329496fe9d8adab7288a0d39895ac0dc0cb7ffe90ed31d30320c172224659c7a67441bd70c4e4d957c4d643862e955367
6
+ metadata.gz: 223fb6d226ef1511e88cac89f0b1176e5db6bd01899b49279012d1ed94e607c28491f4ec770c96848291d84748e6f2b3956812ee0a4f25a3b7a814557f3de259
7
+ data.tar.gz: 52e763ce4e3b3bb7d59881d284f1a136474b46b3cffba722db96f333e63538e7647f638fe5b67c427e5fb6bbdf96452f0dc7b216e04300ffd690d8197302161b
data/README.md CHANGED
@@ -66,7 +66,7 @@ This library extends Active Job with a querying interface and the following sett
66
66
  ## Adapter Specifics
67
67
 
68
68
  - **Resque**: Queue pausing is supported only if you have `resque-pause` installed in your project
69
- - **Solid Queue**: Requires version >= 0.9.
69
+ - **Solid Queue**: Requires version >= 1.0.1.
70
70
 
71
71
  ## Advanced configuration
72
72
 
@@ -25,7 +25,7 @@ table.jobs {
25
25
  width: 45%;
26
26
  }
27
27
  &.scheduled th.job-header {
28
- width: 60%;
28
+ width: 40%;
29
29
  }
30
30
  &.finished th.job-header {
31
31
  width: 65%;
@@ -8,7 +8,7 @@ class MissionControl::Jobs::DiscardsController < MissionControl::Jobs::Applicati
8
8
 
9
9
  private
10
10
  def jobs_relation
11
- ActiveJob.jobs.failed
11
+ ActiveJob.jobs
12
12
  end
13
13
 
14
14
  def redirect_location
@@ -3,11 +3,16 @@ class MissionControl::Jobs::DispatchesController < MissionControl::Jobs::Applica
3
3
 
4
4
  def create
5
5
  @job.dispatch
6
- redirect_to application_jobs_url(@application, :blocked), notice: "Dispatched job with id #{@job.job_id}"
6
+ redirect_to redirect_location, notice: "Dispatched job with id #{@job.job_id}"
7
7
  end
8
8
 
9
9
  private
10
- def jobs_relation
11
- ApplicationJob.jobs.blocked
12
- end
10
+ def jobs_relation
11
+ ActiveJob.jobs
12
+ end
13
+
14
+ def redirect_location
15
+ status = @job.status.presence_in(supported_job_statuses) || :blocked
16
+ application_jobs_url(@application, status)
17
+ end
13
18
  end
@@ -1,6 +1,6 @@
1
1
  class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::ApplicationController
2
2
  before_action :ensure_supported_recurring_tasks
3
- before_action :set_recurring_task, only: :show
3
+ before_action :set_recurring_task, only: [ :show, :update ]
4
4
 
5
5
  def index
6
6
  @recurring_tasks = MissionControl::Jobs::Current.server.recurring_tasks
@@ -10,6 +10,14 @@ class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::App
10
10
  @jobs_page = MissionControl::Jobs::Page.new(@recurring_task.jobs, page: params[:page].to_i)
11
11
  end
12
12
 
13
+ def update
14
+ if (job = @recurring_task.enqueue) && job.successfully_enqueued?
15
+ redirect_to application_job_path(@application, job.job_id), notice: "Enqueued recurring task #{@recurring_task.id}"
16
+ else
17
+ redirect_to application_recurring_task_path(@application, @recurring_task), alert: "Something went wrong enqueuing this recurring task"
18
+ end
19
+ end
20
+
13
21
  private
14
22
  def ensure_supported_recurring_tasks
15
23
  unless recurring_tasks_supported?
@@ -26,7 +26,7 @@ module MissionControl::Jobs::JobsHelper
26
26
  def attribute_names_for_job_status(status)
27
27
  case status.to_s
28
28
  when "failed" then [ "Error", "" ]
29
- when "blocked" then [ "Queue", "Blocked by", "Block expiry", "" ]
29
+ when "blocked" then [ "Queue", "Blocked by", "" ]
30
30
  when "finished" then [ "Queue", "Finished" ]
31
31
  when "scheduled" then [ "Queue", "Scheduled", "" ]
32
32
  when "in_progress" then [ "Queue", "Run by", "Running since" ]
@@ -12,6 +12,10 @@ class MissionControl::Jobs::RecurringTask
12
12
  ActiveJob::JobsRelation.new(queue_adapter: queue_adapter).where(recurring_task_id: id)
13
13
  end
14
14
 
15
+ def enqueue
16
+ queue_adapter.enqueue_recurring_task(id)
17
+ end
18
+
15
19
  private
16
20
  attr_reader :queue_adapter
17
21
  end
@@ -26,6 +26,17 @@
26
26
  <%= formatted_time(job.enqueued_at.to_datetime) %>
27
27
  </td>
28
28
  </tr>
29
+ <% if job.scheduled? %>
30
+ <tr>
31
+ <th>Scheduled</th>
32
+ <td>
33
+ <%= formatted_time(job.scheduled_at) %>
34
+ <% if job_delayed?(job) %>
35
+ <div class="is-danger tag ml-4">delayed</div>
36
+ <% end %>
37
+ </td>
38
+ </tr>
39
+ <% end %>
29
40
  <% if job.failed? %>
30
41
  <tr>
31
42
  <th>Failed</th>
@@ -1,3 +1,3 @@
1
1
  <div class="buttons is-right">
2
- <%= button_to "Dispatch", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %>
2
+ <%= button_to "Run now", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %>
3
3
  </div>
@@ -1,6 +1,7 @@
1
1
  <td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
2
- <td><div class="is-family-monospace is-size-7"><%= job.blocked_by %></div></td>
3
- <td><%= formatted_time(job.blocked_until) %></td>
2
+ <td><div class="is-family-monospace is-size-7"><%= job.blocked_by %></div>
3
+ <div class="has-text-grey is-size-7">Until <%= formatted_time(job.blocked_until) %></div>
4
+ </td>
4
5
  <td class="pr-0">
5
6
  <%= render "mission_control/jobs/jobs/blocked/actions", job: job %>
6
7
  </td>
@@ -1,4 +1,5 @@
1
1
  <div class="buttons is-right">
2
+ <%= button_to "Run now", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %>
2
3
  <%= button_to "Discard", application_job_discard_path(@application, job.job_id), class: "button is-danger is-light mr-0",
3
4
  form: { data: { turbo_confirm: "This will delete the job and can't be undone. Are you sure?" } } %>
4
5
  </div>
@@ -0,0 +1,3 @@
1
+ <div class="buttons is-right">
2
+ <%= button_to "Run now", application_recurring_task_path(@application, recurring_task.id), class: "button is-warning is-light mr-0", method: :put %>
3
+ </div>
@@ -16,4 +16,7 @@
16
16
  <td> <%= recurring_task.schedule %> </td>
17
17
  <td><div class="has-text-grey"><%= recurring_task.last_enqueued_at ? formatted_time(recurring_task.last_enqueued_at) : "Never" %></div></td>
18
18
  <td class="next_time"><div class="has-text-grey"><%= formatted_time(recurring_task.next_time) %></div></td>
19
+ <td class="pr-0">
20
+ <%= render "mission_control/jobs/recurring_tasks/actions", recurring_task: recurring_task %>
21
+ </td>
19
22
  </tr>
@@ -3,5 +3,8 @@
3
3
  <div class="level-left">
4
4
  <%= recurring_task.id %>
5
5
  </div>
6
+ <div class="level-right">
7
+ <%= render "mission_control/jobs/recurring_tasks/actions", recurring_task: recurring_task %>
8
+ </div>
6
9
  </div>
7
10
  </h1>
@@ -7,8 +7,9 @@
7
7
  <th></th>
8
8
  <th>Job</th>
9
9
  <th>Schedule</th>
10
- <th>Last enqueued at</th>
11
- <th>Next run</th>
10
+ <th>Last enqueued</th>
11
+ <th>Next</th>
12
+ <th></th>
12
13
  </tr>
13
14
  </thead>
14
15
 
data/config/routes.rb CHANGED
@@ -20,7 +20,7 @@ MissionControl::Jobs::Engine.routes.draw do
20
20
  resources :jobs, only: :index, path: ":status/jobs"
21
21
 
22
22
  resources :workers, only: [ :index, :show ]
23
- resources :recurring_tasks, only: [ :index, :show ]
23
+ resources :recurring_tasks, only: [ :index, :show, :update ]
24
24
  end
25
25
 
26
26
  # Allow referencing urls without providing an application_id. It will default to the first one.
@@ -25,7 +25,7 @@ module ActiveJob::Executing
25
25
  end
26
26
 
27
27
  def dispatch
28
- ActiveJob.jobs.blocked.dispatch_job(self)
28
+ ActiveJob.jobs.dispatch_job(self)
29
29
  end
30
30
 
31
31
  private
@@ -154,7 +154,12 @@ class ActiveJob::JobsRelation
154
154
  end
155
155
 
156
156
  # Dispatch the provided job.
157
+ #
158
+ # This operation is only valid for blocked or scheduled jobs. It will
159
+ # raise an error +ActiveJob::Errors::InvalidOperation+ otherwise.
157
160
  def dispatch_job(job)
161
+ raise ActiveJob::Errors::InvalidOperation, "This operation can only be performed on blocked or scheduled jobs, but this job is #{job.status}" unless job.blocked? || job.scheduled?
162
+
158
163
  queue_adapter.dispatch_job(job, self)
159
164
  end
160
165
 
@@ -20,6 +20,12 @@ module ActiveJob::QueueAdapters::SolidQueueExt::RecurringTasks
20
20
  end
21
21
  end
22
22
 
23
+ def enqueue_recurring_task(task_id)
24
+ if task = SolidQueue::RecurringTask.find_by(key: task_id)
25
+ task.enqueue(at: Time.now)
26
+ end
27
+ end
28
+
23
29
  private
24
30
  def recurring_task_attributes_from_solid_queue_recurring_task(task)
25
31
  {
@@ -123,9 +123,13 @@ module ActiveJob::QueueAdapters::SolidQueueExt
123
123
  end
124
124
 
125
125
  def dispatch_immediately(job)
126
- SolidQueue::Job.transaction do
127
- job.dispatch_bypassing_concurrency_limits
128
- job.blocked_execution.destroy!
126
+ if job.blocked?
127
+ SolidQueue::Job.transaction do
128
+ job.dispatch_bypassing_concurrency_limits
129
+ job.blocked_execution.destroy!
130
+ end
131
+ else
132
+ job.scheduled_execution.update!(scheduled_at: Time.now)
129
133
  end
130
134
  end
131
135
 
@@ -1,5 +1,5 @@
1
1
  module MissionControl
2
2
  module Jobs
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mission_control-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Manrubia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-06 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.0'
159
+ version: 1.0.1
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.0'
166
+ version: 1.0.1
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: selenium-webdriver
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -425,6 +425,7 @@ files:
425
425
  - app/views/mission_control/jobs/queues/_queue_title.html.erb
426
426
  - app/views/mission_control/jobs/queues/index.html.erb
427
427
  - app/views/mission_control/jobs/queues/show.html.erb
428
+ - app/views/mission_control/jobs/recurring_tasks/_actions.html.erb
428
429
  - app/views/mission_control/jobs/recurring_tasks/_general_information.html.erb
429
430
  - app/views/mission_control/jobs/recurring_tasks/_recurring_task.html.erb
430
431
  - app/views/mission_control/jobs/recurring_tasks/_title.html.erb