Skip to content

Commit 3025376

Browse files
Merge branch 'main' of github.com:rafael-pissardo/mission_control-jobs into jobs-count-on-index
2 parents 2a4f68d + 7ac3835 commit 3025376

File tree

32 files changed

+315
-82
lines changed

32 files changed

+315
-82
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GIT
1515
PATH
1616
remote: .
1717
specs:
18-
mission_control-jobs (1.0.2)
18+
mission_control-jobs (1.1.0)
1919
actioncable (>= 7.1)
2020
actionpack (>= 7.1)
2121
activejob (>= 7.1)

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ For example, if you're using the Dockerfile generated by Rails with an API-only
5454
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5555
```
5656

57-
*Note: Legacy CSS bundlers `sass-rails` and `sassc-rails` may fail to compile some of the CSS vendored into this library from [Bulma](https://github.com/jgthms/bulma), which was created in [Dart SASS](https://sass-lang.com/dart-sass/). You will therefore need to upgrade to `dartsass-rails` or some library that relies on it, like `cssbundling-rails`.*
58-
5957
### Authentication
6058

6159
Mission Control comes with **HTTP basic authentication enabled and closed** by default. Credentials are stored in [Rails's credentials](https://edgeguides.rubyonrails.org/security.html#custom-credentials) like this:
@@ -76,6 +74,15 @@ To set them up for different environments you can use the `RAILS_ENV` environmen
7674
RAILS_ENV=production bin/rails mission_control:jobs:authentication:configure
7775
```
7876

77+
User and password can also be configured by hand like this:
78+
79+
```ruby
80+
Rails.application.configure do
81+
MissionControl::Jobs.http_basic_auth_user = "dev"
82+
MissionControl::Jobs.http_basic_auth_password = "secret"
83+
end
84+
```
85+
7986
#### Custom authentication
8087

8188
You can provide your own authentication mechanism, for example, if you have a certain type of admin user in your app that can access Mission Control. To make this easier, you can specify a different controller as the base class for Mission Control's controllers. By default, Mission Control's controllers will extend the host app's `ApplicationController`, but you can change this easily:
@@ -107,6 +114,7 @@ Besides `base_controller_class`, you can also set the following for `MissionCont
107114
- `scheduled_job_delay_threshold`: the time duration before a scheduled job is considered delayed. Defaults to `1.minute` (a job is considered delayed if it hasn't transitioned from the `scheduled` status 1 minute after the scheduled time).
108115
- `show_console_help`: whether to show the console help. If you don't want the console help message, set this to `false`—defaults to `true`.
109116
- `backtrace_cleaner`: a backtrace cleaner used for optionally filtering backtraces on the Failed Jobs detail page. Defaults to `Rails::BacktraceCleaner.new`. See the [Advanced configuration](#advanced-configuration) section for how to configure/override this setting on a per application/server basis.
117+
- `filter_arguments`: an array of strings representing the job argument keys you want to filter out in the UI. This is useful for hiding sensitive user data. Currently, only root-level hash keys are supported.
110118

111119
This library extends Active Job with a querying interface and the following setting:
112120
- `config.active_job.default_page_size`: the internal batch size that Active Job will use when sending queries to the underlying adapter and the batch size for the bulk operations defined above—defaults to `1000`.
@@ -158,19 +166,19 @@ SERVERS_BY_APP.each do |app, servers|
158166
end
159167

160168
# Default:
161-
#
169+
#
162170
# @return Array<String, ActiveJob::QueueAdapters::Base)
163171
# An array where:
164172
# * the String represents the symbolic name for this server within the UI
165173
# * ActiveJob::QueueAdapters::Base adapter instance used to access this Application Server/Service
166-
[ server, queue_adapter ]
167-
174+
[ server, queue_adapter ]
175+
168176
# Optional return formats:
169-
#
177+
#
170178
# @return Array<String, Array<ActiveJob::QueueAdapters::Base>>
171-
# * This is equivalent, and behaves identically to, the format the default format above.
179+
# * This is equivalent, and behaves identically to, the format the default format above.
172180
# [ server, [ queue_adapter ]] # without optional backtrace cleaner
173-
#
181+
#
174182
# @return Array<String, Array<ActiveJob::QueueAdapters::Base, ActiveSupport::BacktraceCleaner>>
175183
# * This format adds an optional ActiveSupport::BacktraceCleaner to override the system wide
176184
# backtrace cleaner for *this* Application Server/Service.
@@ -246,7 +254,7 @@ Available job servers:
246254

247255
And then:
248256
```
249-
>> connect_to "hey:solid_queue"
257+
>> connect_to hey:solid_queue
250258
Connected to hey:solid_queue
251259
```
252260

app/controllers/concerns/mission_control/jobs/job_filters.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module MissionControl::Jobs::JobFilters
44
included do
55
before_action :set_filters
66

7-
helper_method :active_filters?
7+
helper_method :active_filters?, :jobs_filter_param
88
end
99

1010
private
@@ -20,6 +20,14 @@ def active_filters?
2020
@job_filters.any?
2121
end
2222

23+
def jobs_filter_param
24+
if @job_filters&.any?
25+
{ filter: @job_filters }
26+
else
27+
{}
28+
end
29+
end
30+
2331
def finished_at_range_params
2432
range_start, range_end = params.dig(:filter, :finished_at_start), params.dig(:filter, :finished_at_end)
2533
if range_start || range_end
@@ -28,6 +36,6 @@ def finished_at_range_params
2836
end
2937

3038
def parse_with_time_zone(date)
31-
DateTime.parse(date).in_time_zone if date.present?
39+
Time.zone.parse(date) if date.present?
3240
end
3341
end

app/controllers/mission_control/jobs/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class MissionControl::Jobs::ApplicationController < MissionControl::Jobs.base_co
1212
include MissionControl::Jobs::BasicAuthentication
1313
include MissionControl::Jobs::ApplicationScoped, MissionControl::Jobs::NotFoundRedirections
1414
include MissionControl::Jobs::AdapterFeatures
15+
include MissionControl::Jobs::JobFilters
1516

1617
around_action :set_current_locale
1718

app/controllers/mission_control/jobs/discards_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ def jobs_relation
1313

1414
def redirect_location
1515
status = @job.status.presence_in(supported_job_statuses) || :failed
16-
application_jobs_url(@application, status)
16+
application_jobs_url(@application, status, **jobs_filter_param)
1717
end
1818
end

app/controllers/mission_control/jobs/jobs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class MissionControl::Jobs::JobsController < MissionControl::Jobs::ApplicationController
2-
include MissionControl::Jobs::JobScoped, MissionControl::Jobs::JobFilters
2+
include MissionControl::Jobs::JobScoped
33

44
skip_before_action :set_job, only: :index
55

app/controllers/mission_control/jobs/retries_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class MissionControl::Jobs::RetriesController < MissionControl::Jobs::Applicatio
33

44
def create
55
@job.retry
6-
redirect_to application_jobs_url(@application, :failed), notice: "Retried job with id #{@job.job_id}"
6+
redirect_to application_jobs_url(@application, :failed, **jobs_filter_param), notice: "Retried job with id #{@job.job_id}"
77
end
88

99
private

app/helpers/mission_control/jobs/jobs_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def as_renderable_hash(argument)
6767
elsif argument["_aj_serialized"]
6868
ActiveJob::Arguments.deserialize([ argument ]).first
6969
else
70-
argument.without("_aj_symbol_keys", "_aj_ruby2_keywords")
70+
MissionControl::Jobs.job_arguments_filter.apply_to(argument)
71+
.without("_aj_symbol_keys", "_aj_ruby2_keywords")
7172
.transform_values { |v| as_renderable_argument(v) }
7273
.map { |k, v| "#{k}: #{v}" }
7374
.join(", ")

app/helpers/mission_control/jobs/navigation_helper.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ def selected_server?(server)
3737
MissionControl::Jobs::Current.server.name == server.name
3838
end
3939

40-
def jobs_filter_param
41-
if @job_filters&.any?
42-
{ filter: @job_filters }
43-
else
44-
{}
45-
end
46-
end
47-
4840
def jobs_count_with_status(status)
4941
count = ActiveJob.jobs.with_status(status).count
5042
if count.infinite?

app/views/layouts/mission_control/jobs/_application_selection.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<nav class="navbar" role="navigation" aria-label="main navigation">
22
<div class="navbar-menu is-active mb-4">
33
<div class="navbar-start">
4+
<% if defined?(main_app.root_path) %>
5+
<%= link_to "Back to main app", main_app.root_path %>
6+
<% end %>
47
</div>
58

69
<div class="navbar-end">

0 commit comments

Comments
 (0)