mission_control-jobs 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,14 @@
1
1
  class MissionControl::Jobs::ApplicationController < MissionControl::Jobs.base_controller_class.constantize
2
+ ActionController::Base::MODULES.each do |mod|
3
+ include mod unless self < mod
4
+ end
5
+
2
6
  layout "mission_control/jobs/application"
3
7
 
8
+ # Include helpers if not already included
9
+ helper MissionControl::Jobs::ApplicationHelper unless self < MissionControl::Jobs::ApplicationHelper
10
+ helper Importmap::ImportmapTagsHelper unless self < Importmap::ImportmapTagsHelper
11
+
4
12
  include MissionControl::Jobs::ApplicationScoped, MissionControl::Jobs::NotFoundRedirections
5
13
  include MissionControl::Jobs::AdapterFeatures
6
14
 
@@ -15,7 +15,6 @@ class MissionControl::Jobs::JobsController < MissionControl::Jobs::ApplicationCo
15
15
  end
16
16
 
17
17
  private
18
-
19
18
  def jobs_relation
20
19
  filtered_jobs
21
20
  end
@@ -1,6 +1,7 @@
1
1
  class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::ApplicationController
2
2
  before_action :ensure_supported_recurring_tasks
3
3
  before_action :set_recurring_task, only: [ :show, :update ]
4
+ before_action :ensure_recurring_task_can_be_enqueued, only: :update
4
5
 
5
6
  def index
6
7
  @recurring_tasks = MissionControl::Jobs::Current.server.recurring_tasks
@@ -14,7 +15,7 @@ class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::App
14
15
  if (job = @recurring_task.enqueue) && job.successfully_enqueued?
15
16
  redirect_to application_job_path(@application, job.job_id), notice: "Enqueued recurring task #{@recurring_task.id}"
16
17
  else
17
- redirect_to application_recurring_task_path(@application, @recurring_task), alert: "Something went wrong enqueuing this recurring task"
18
+ redirect_to application_recurring_task_path(@application, @recurring_task.id), alert: "Something went wrong enqueuing this recurring task"
18
19
  end
19
20
  end
20
21
 
@@ -28,4 +29,10 @@ class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::App
28
29
  def set_recurring_task
29
30
  @recurring_task = MissionControl::Jobs::Current.server.find_recurring_task(params[:id])
30
31
  end
32
+
33
+ def ensure_recurring_task_can_be_enqueued
34
+ unless @recurring_task.runnable?
35
+ redirect_to application_recurring_task_path(@application, @recurring_task.id), alert: "This task can't be enqueued"
36
+ end
37
+ end
31
38
  end
@@ -39,7 +39,6 @@ module MissionControl::Jobs::JobsHelper
39
39
  end
40
40
 
41
41
  private
42
-
43
42
  def renderable_job_arguments_for(job)
44
43
  job.serialized_arguments.collect do |argument|
45
44
  as_renderable_argument(argument)
@@ -53,7 +52,7 @@ module MissionControl::Jobs::JobsHelper
53
52
  when Array
54
53
  as_renderable_array(argument)
55
54
  else
56
- ActiveJob::Arguments.deserialize([ argument ])
55
+ ActiveJob::Arguments.deserialize([ argument ]).first
57
56
  end
58
57
  rescue ActiveJob::DeserializationError
59
58
  argument.to_s
@@ -65,12 +64,18 @@ module MissionControl::Jobs::JobsHelper
65
64
  argument["_aj_globalid"]
66
65
  elsif argument["_aj_serialized"] == "ActiveJob::Serializers::ModuleSerializer"
67
66
  argument["value"]
67
+ elsif argument["_aj_serialized"]
68
+ ActiveJob::Arguments.deserialize([ argument ]).first
68
69
  else
69
- ActiveJob::Arguments.deserialize([ argument ])
70
+ argument.without("_aj_symbol_keys", "_aj_ruby2_keywords")
71
+ .transform_values { |v| as_renderable_argument(v) }
72
+ .map { |k, v| "#{k}: #{v}" }
73
+ .join(", ")
74
+ .then { |s| "{#{s}}" }
70
75
  end
71
76
  end
72
77
 
73
78
  def as_renderable_array(argument)
74
- "(#{argument.collect { |part| as_renderable_argument(part) }.join(", ")})"
79
+ "[#{argument.collect { |part| as_renderable_argument(part) }.join(", ")}]"
75
80
  end
76
81
  end
@@ -16,6 +16,10 @@ class MissionControl::Jobs::RecurringTask
16
16
  queue_adapter.enqueue_recurring_task(id)
17
17
  end
18
18
 
19
+ def runnable?
20
+ queue_adapter.can_enqueue_recurring_task?(id)
21
+ end
22
+
19
23
  private
20
24
  attr_reader :queue_adapter
21
25
  end
@@ -7,7 +7,8 @@
7
7
 
8
8
  <meta name="viewport" content="width=device-width,initial-scale=1">
9
9
  <meta name="turbo-cache-control" content="no-cache">
10
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.1/css/bulma.min.css">
10
+
11
+ <%= stylesheet_link_tag "mission_control/jobs/bulma.min" %>
11
12
  <%= stylesheet_link_tag "mission_control/jobs/application", "data-turbo-track": "reload" %>
12
13
  <%= javascript_importmap_tags "application", importmap: MissionControl::Jobs.importmap %>
13
14
  </head>
@@ -1,3 +1,5 @@
1
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 %>
2
+ <% if recurring_task.runnable? %>
3
+ <%= button_to "Run now", application_recurring_task_path(@application, recurring_task.id), class: "button is-warning is-light mr-0", method: :put %>
4
+ <% end %>
3
5
  </div>
@@ -26,6 +26,12 @@ module ActiveJob::QueueAdapters::SolidQueueExt::RecurringTasks
26
26
  end
27
27
  end
28
28
 
29
+ def can_enqueue_recurring_task?(task_id)
30
+ if task = SolidQueue::RecurringTask.find_by(key: task_id)
31
+ task.valid?
32
+ end
33
+ end
34
+
29
35
  private
30
36
  def recurring_task_attributes_from_solid_queue_recurring_task(task)
31
37
  {
@@ -7,6 +7,13 @@ module MissionControl
7
7
  class Engine < ::Rails::Engine
8
8
  isolate_namespace MissionControl::Jobs
9
9
 
10
+ initializer "mission_control-jobs.middleware" do |app|
11
+ if app.config.api_only
12
+ app.middleware.use ActionDispatch::Flash
13
+ app.middleware.use ::Rack::MethodOverride
14
+ end
15
+ end
16
+
10
17
  config.mission_control = ActiveSupport::OrderedOptions.new unless config.try(:mission_control)
11
18
  config.mission_control.jobs = ActiveSupport::OrderedOptions.new
12
19
 
@@ -80,6 +87,7 @@ module MissionControl
80
87
  end
81
88
 
82
89
  initializer "mission_control-jobs.assets" do |app|
90
+ app.config.assets.paths << root.join("app/assets/stylesheets")
83
91
  app.config.assets.paths << root.join("app/javascript")
84
92
  app.config.assets.precompile += %w[ mission_control_jobs_manifest ]
85
93
  end
@@ -1,5 +1,5 @@
1
1
  module MissionControl
2
2
  module Jobs
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.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.5.0
4
+ version: 0.6.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-08 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -305,7 +305,7 @@ dependencies:
305
305
  - !ruby/object:Gem::Version
306
306
  version: '0'
307
307
  - !ruby/object:Gem::Dependency
308
- name: sprockets-rails
308
+ name: propshaft
309
309
  requirement: !ruby/object:Gem::Requirement
310
310
  requirements:
311
311
  - - ">="
@@ -358,6 +358,7 @@ files:
358
358
  - Rakefile
359
359
  - app/assets/config/mission_control_jobs_manifest.js
360
360
  - app/assets/stylesheets/mission_control/jobs/application.css
361
+ - app/assets/stylesheets/mission_control/jobs/bulma.min.css
361
362
  - app/assets/stylesheets/mission_control/jobs/forms.css
362
363
  - app/assets/stylesheets/mission_control/jobs/jobs.css
363
364
  - app/controllers/concerns/mission_control/jobs/adapter_features.rb