job_harbor 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f0c268baa8edeba11da95a83b4974f8c66ec8ea963f25855239820ae56c0bce
4
- data.tar.gz: a3cecd5265326cae8dc754f57b08a4353616d22f484ba6b8d2183c5c9601d71f
3
+ metadata.gz: 303b8b53351a0bd2896009dda7f389fe5e765605e2c78886b87f6a27f01b2f3c
4
+ data.tar.gz: 2fd071bf4835ad91ebc52073e336a3cbeddd7f5e0866aadcd0dede99093252a9
5
5
  SHA512:
6
- metadata.gz: 34e2aee38592bf4879198ffe4818db9da946537ae42fa34df83ddb692aff4cf7d16e2e4b0bd5771677f06eea0b83201a8f590ba01b60d9d6424fc09400516753
7
- data.tar.gz: 43552b22b9d475a4da6455e26b2a674dfffadc09988bd96bf9faba6656de1eff5055342ba60d0114817dfef89da01a81cda5672da5906f89fac7fdbe144736f6
6
+ metadata.gz: 89a51954fd2a53480352be425d426bae9227cd8646b74e61061f4165526ff1401604f802f1ac7a06d09a46c390e3ec6de7e3e96f46cd9ce4cb52c20ef76f01ab
7
+ data.tar.gz: 59e555d78e06142e67e941c2494a932a567dfa68fd7e6fdb8885b74c4aa0851bf3026fa9fc1a1d4da9df28ce3c21856b26c2d7a38add48b134fb87a066d2e2ed
data/README.md CHANGED
@@ -75,6 +75,15 @@ Then run:
75
75
  bundle install
76
76
  ```
77
77
 
78
+ Generate the initializer:
79
+
80
+ ```bash
81
+ bin/rails generate job_harbor:install
82
+ ```
83
+
84
+ This creates `config/initializers/job_harbor.rb` with every setting commented out at its
85
+ default, so installing it changes nothing until you uncomment a line.
86
+
78
87
  ## Mounting
79
88
 
80
89
  Mount the engine in your routes:
@@ -96,7 +105,7 @@ end
96
105
 
97
106
  ## Configuration
98
107
 
99
- Create an initializer at `config/initializers/job_harbor.rb`:
108
+ Settings live in `config/initializers/job_harbor.rb`, created by `bin/rails generate job_harbor:install`:
100
109
 
101
110
  ```ruby
102
111
  JobHarbor.configure do |config|
@@ -47,10 +47,7 @@ module JobHarbor
47
47
 
48
48
  def return_to_app_path
49
49
  configured = sq_config.return_to_app_path
50
- return configured if configured.is_a?(String)
51
- return instance_exec(&configured) if configured.respond_to?(:call)
52
-
53
- main_app.root_path
50
+ (configured.respond_to?(:call) ? instance_exec(&configured) : configured).presence
54
51
  rescue
55
52
  "/"
56
53
  end
@@ -15,6 +15,7 @@ module JobHarbor
15
15
  def show
16
16
  executions = SolidQueue::RecurringExecution.where(task_key: @task.key)
17
17
  @task_arguments = RecurringTaskArguments.new(@task)
18
+ @task_queue = RecurringTaskQueue.new(@task)
18
19
  @executions_count = executions.count
19
20
  @last_run_at = executions.maximum(:run_at)
20
21
  @recent_executions = executions.order(run_at: :desc).limit(RECENT_EXECUTIONS_LIMIT)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JobHarbor
4
+ class RecurringTaskQueue
5
+ def initialize(task)
6
+ @task = task
7
+ end
8
+
9
+ # SQ stores queue_name only when recurring.yml sets one; otherwise the job class's queue_as decides.
10
+ def name
11
+ @task.queue_name.presence || job_class_queue_name
12
+ end
13
+
14
+ private
15
+
16
+ # A queue_as block may read arguments we don't pass, so a raising block means we can't know the queue.
17
+ def job_class_queue_name
18
+ job_class&.new&.queue_name
19
+ rescue StandardError
20
+ nil
21
+ end
22
+
23
+ # Mirrors SQ's RecurringTask#job_class: a command task runs on SQ's default job class.
24
+ def job_class
25
+ return SolidQueue::RecurringTask.default_job_class if @task.class_name.blank?
26
+
27
+ klass = @task.class_name.safe_constantize
28
+ klass if klass.is_a?(Class) && klass < ActiveJob::Base
29
+ end
30
+ end
31
+ end
@@ -23,7 +23,7 @@
23
23
  <td><%= link_to task.key, recurring_task_path(task), class: "link font-medium" %></td>
24
24
  <td><code class="text-sm font-mono"><%= task.class_name %></code></td>
25
25
  <td class="text-sm"><%= task.schedule %></td>
26
- <td class="text-sm"><%= task.queue_name || "default" %></td>
26
+ <td class="text-sm"><%= JobHarbor::RecurringTaskQueue.new(task).name || "—" %></td>
27
27
  <td>
28
28
  <%= button_to "Run Now", enqueue_now_recurring_task_path(task), method: :post, class: "btn btn-secondary btn-xs" %>
29
29
  </td>
@@ -19,7 +19,7 @@
19
19
 
20
20
  <%= render JobHarbor::InfoLineComponent.new(label: "Schedule", value: @task.schedule) %>
21
21
 
22
- <%= render JobHarbor::InfoLineComponent.new(label: "Queue", value: @task.queue_name || "default") %>
22
+ <%= render JobHarbor::InfoLineComponent.new(label: "Queue", value: @task_queue.name || "—") %>
23
23
 
24
24
  <% if @task_arguments.present? %>
25
25
  <div class="mt-3">
@@ -58,10 +58,12 @@
58
58
  <%= render JobHarbor::RefreshSelectorComponent.new %>
59
59
  <% end %>
60
60
  <%= render JobHarbor::ThemeToggleComponent.new %>
61
- <a href="<%= return_to_app_path %>" class="btn btn-outline btn-sm" title="<%= return_to_app_label %>">
62
- <svg class="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
63
- <span class="hidden sm:inline"><%= return_to_app_label %></span>
64
- </a>
61
+ <% if (back_path = return_to_app_path) %>
62
+ <a href="<%= back_path %>" class="btn btn-outline btn-sm" title="<%= return_to_app_label %>">
63
+ <svg class="w-3.5 h-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
64
+ <span class="hidden sm:inline"><%= return_to_app_label %></span>
65
+ </a>
66
+ <% end %>
65
67
  </div>
66
68
  </nav>
67
69
 
@@ -0,0 +1,22 @@
1
+ require "rails/generators"
2
+
3
+ module JobHarbor
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ desc "Creates a JobHarbor initializer at config/initializers/job_harbor.rb with every setting at its default."
9
+
10
+ def copy_initializer
11
+ template "job_harbor.rb", "config/initializers/job_harbor.rb"
12
+ end
13
+
14
+ def show_next_steps
15
+ say "\nMount the dashboard in config/routes.rb:"
16
+ say %( mount JobHarbor::Engine, at: "/job_harbor")
17
+ say "\nThen set config.authorize_with in config/initializers/job_harbor.rb."
18
+ say "Until you do, the dashboard denies every request outside development and test.\n"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ # JobHarbor configuration. Every setting below is shown at its default; uncomment one to change it.
2
+ # See https://github.com/esparkman/job_harbor#configuration for details.
3
+ JobHarbor.configure do |config|
4
+ # Authorization: a lambda run in the dashboard controller (instance_exec), so it can call your
5
+ # app's helpers such as current_user. Return a truthy value to allow the request.
6
+ # Unset, the dashboard is open in development and test and denied in every other environment.
7
+ # config.authorize_with = nil
8
+ # For example: config.authorize_with = -> { current_user&.admin? }
9
+
10
+ # Theme: :dark or :light
11
+ # config.theme = :dark
12
+
13
+ # Jobs per page
14
+ # config.jobs_per_page = 25
15
+
16
+ # Auto-refresh polling interval in seconds.
17
+ # The selector offers Off, 15, 30, 60 and 300; any other value is added as its own option.
18
+ # config.poll_interval = 30
19
+
20
+ # Features
21
+ # config.enable_recurring_tasks = true
22
+ # config.enable_real_time_updates = true # false removes auto-refresh entirely
23
+ # config.enable_failure_stats = true
24
+ # config.enable_charts = true
25
+
26
+ # Default chart time range
27
+ # config.default_chart_range = "24h"
28
+
29
+ # "Back to App" link in the navbar, hidden until set. Takes a path or a proc run in the dashboard
30
+ # controller; a blank result hides the link.
31
+ # config.return_to_app_path = nil
32
+ # For example: config.return_to_app_path = -> { main_app.root_path }
33
+ # config.return_to_app_label = "Back to App"
34
+
35
+ # Sensitive values in job arguments, payloads and recurring task arguments.
36
+ # nil uses your app's config.filter_parameters; an Array of Strings, Symbols, Regexps and Procs
37
+ # replaces that list; false shows raw values and brings back searching by argument.
38
+ # config.filter_parameters = nil
39
+ end
@@ -1,3 +1,3 @@
1
1
  module JobHarbor
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: job_harbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Sparkman
@@ -111,6 +111,7 @@ files:
111
111
  - app/models/job_harbor/processes.rb
112
112
  - app/models/job_harbor/queue_stats.rb
113
113
  - app/models/job_harbor/recurring_task_arguments.rb
114
+ - app/models/job_harbor/recurring_task_queue.rb
114
115
  - app/models/job_harbor/sensitive_value_filter.rb
115
116
  - app/views/job_harbor/dashboard/index.html.erb
116
117
  - app/views/job_harbor/jobs/index.html.erb
@@ -123,6 +124,8 @@ files:
123
124
  - app/views/job_harbor/workers/index.html.erb
124
125
  - app/views/layouts/job_harbor/application.html.erb
125
126
  - config/routes.rb
127
+ - lib/generators/job_harbor/install/install_generator.rb
128
+ - lib/generators/job_harbor/install/templates/job_harbor.rb.tt
126
129
  - lib/job_harbor.rb
127
130
  - lib/job_harbor/configuration.rb
128
131
  - lib/job_harbor/engine.rb