Skip to content

Commit 9923a74

Browse files
authored
Merge pull request #146 from ikyn-inc/backtrace_cleaner
undefined
2 parents af683b3 + 927ae8c commit 9923a74

File tree

11 files changed

+124
-7
lines changed

11 files changed

+124
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/test/dummy/storage/
1010
/test/dummy/tmp/
1111
.DS_Store
12+
.ruby-gemset

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Besides `base_controller_class`, you can also set the following for `MissionCont
5757
- `internal_query_count_limit`: in count queries, the maximum number of records that will be counted if the adapter needs to limit these queries. True counts above this number will be returned as `INFINITY`. This keeps count queries fast—defaults to `500,000`
5858
- `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).
5959
- `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`.
60+
- `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.
6061

6162
This library extends Active Job with a querying interface and the following setting:
6263
- `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`.
@@ -107,7 +108,24 @@ SERVERS_BY_APP.each do |app, servers|
107108
ActiveJob::QueueAdapters::SolidQueueAdapter.new
108109
end
109110

110-
[ server, queue_adapter ]
111+
# Default:
112+
#
113+
# @return Array<String, ActiveJob::QueueAdapters::Base)
114+
# An array where:
115+
# * the String represents the symbolic name for this server within the UI
116+
# * ActiveJob::QueueAdapters::Base adapter instance used to access this Application Server/Service
117+
[ server, queue_adapter ]
118+
119+
# Optional return formats:
120+
#
121+
# @return Array<String, Array<ActiveJob::QueueAdapters::Base>>
122+
# * This is equivalent, and behaves identically to, the format the default format above.
123+
# [ server, [ queue_adapter ]] # without optional backtrace cleaner
124+
#
125+
# @return Array<String, Array<ActiveJob::QueueAdapters::Base, ActiveSupport::BacktraceCleaner>>
126+
# * This format adds an optional ActiveSupport::BacktraceCleaner to override the system wide
127+
# backtrace cleaner for *this* Application Server/Service.
128+
# [ server, [ queue_adapter, BacktraceCleaner.new ]] # with optional backtrace cleaner
111129
end.to_h
112130

113131
MissionControl::Jobs.applications.add(app, queue_adapters_by_name)

app/controllers/mission_control/jobs/jobs_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def show
1515
end
1616

1717
private
18+
1819
def jobs_relation
1920
filtered_jobs
2021
end

app/helpers/mission_control/jobs/jobs_helper.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ def failed_job_error(job)
1111
"#{job.last_execution_error.error_class}: #{job.last_execution_error.message}"
1212
end
1313

14-
def failed_job_backtrace(job)
15-
job.last_execution_error.backtrace.join("\n")
14+
def clean_backtrace?
15+
params["clean_backtrace"] == "true"
16+
end
17+
18+
def failed_job_backtrace(job, server)
19+
if clean_backtrace? && server&.backtrace_cleaner
20+
server.backtrace_cleaner.clean(job.last_execution_error.backtrace).join("\n")
21+
else
22+
job.last_execution_error.backtrace.join("\n")
23+
end
1624
end
1725

1826
def attribute_names_for_job_status(status)
@@ -31,6 +39,7 @@ def job_delayed?(job)
3139
end
3240

3341
private
42+
3443
def renderable_job_arguments_for(job)
3544
job.serialized_arguments.collect do |argument|
3645
as_renderable_argument(argument)

app/views/mission_control/jobs/jobs/_error_information.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
</tbody>
1515
</table>
1616

17-
<pre class="is-family-monospace mb-4"><%= failed_job_backtrace(job) %></pre>
17+
<% if @server.backtrace_cleaner %>
18+
<%= render "mission_control/jobs/jobs/failed/backtrace_toggle", application: @application, job: job %>
19+
<% end %>
20+
21+
<pre class="is-family-monospace mb-4 backtrace-content"><%= failed_job_backtrace(job, @server) %></pre>
1822
<% end %>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<%# locals: (application:, job:) %>
2+
3+
<div class="is-flex is-justify-content-flex-end mb-2 mr-2 backtrace-toggle-selector">
4+
<div class="tabs is-toggle is-toggle-rounded is-small">
5+
<ul>
6+
<li class="<%= class_names('backtrace-clean-link', 'is-active' => clean_backtrace?) %>">
7+
<%= link_to "Clean", application_job_path(application, job.job_id, clean_backtrace: true) %>
8+
</li>
9+
<li class="<%= class_names('backtrace-full-link', 'is-active' => !clean_backtrace?) %>">
10+
<%= link_to "Full", application_job_path(application, job.job_id, clean_backtrace: false) %>
11+
</li>
12+
</ul>
13+
</div>
14+
</div>

lib/mission_control/jobs.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ module Jobs
1919
mattr_accessor :internal_query_count_limit, default: 500_000 # Hard limit to keep unlimited count queries fast enough
2020
mattr_accessor :show_console_help, default: true
2121
mattr_accessor :scheduled_job_delay_threshold, default: 1.minute
22+
mattr_accessor :backtrace_cleaner
2223
end
2324
end

lib/mission_control/jobs/application.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def initialize(name:)
1111

1212
def add_servers(queue_adapters_by_name)
1313
queue_adapters_by_name.each do |name, queue_adapter|
14-
servers << MissionControl::Jobs::Server.new(name: name.to_s, queue_adapter: queue_adapter, application: self)
14+
adapter, cleaner = queue_adapter
15+
16+
servers << MissionControl::Jobs::Server.new(name: name.to_s, queue_adapter: adapter,
17+
backtrace_cleaner: cleaner, application: self)
1518
end
1619
end
1720
end

lib/mission_control/jobs/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Engine < ::Rails::Engine
1515

1616
config.before_initialize do
1717
config.mission_control.jobs.applications = MissionControl::Jobs::Applications.new
18+
config.mission_control.jobs.backtrace_cleaner ||= Rails::BacktraceCleaner.new
1819

1920
config.mission_control.jobs.each do |key, value|
2021
MissionControl::Jobs.public_send("#{key}=", value)

lib/mission_control/jobs/server.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ class MissionControl::Jobs::Server
44
include MissionControl::Jobs::IdentifiedByName
55
include Serializable, RecurringTasks, Workers
66

7-
attr_reader :name, :queue_adapter, :application
7+
attr_reader :name, :queue_adapter, :application, :backtrace_cleaner
88

9-
def initialize(name:, queue_adapter:, application:)
9+
def initialize(name:, queue_adapter:, application:, backtrace_cleaner: nil)
1010
super(name: name)
1111
@queue_adapter = queue_adapter
1212
@application = application
13+
@backtrace_cleaner = backtrace_cleaner || MissionControl::Jobs.backtrace_cleaner
1314
end
1415

1516
def activating(&block)

0 commit comments

Comments
 (0)