Skip to content

Commit 46f66de

Browse files
committed
Move error classes to their own files so they can be loaded by Zeitwerk
Closes #313
1 parent e580fe7 commit 46f66de

File tree

6 files changed

+40
-27
lines changed

6 files changed

+40
-27
lines changed

app/models/solid_queue/process/prunable.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# frozen_string_literal: true
22

33
module SolidQueue
4-
class ProcessPrunedError < RuntimeError
5-
def initialize(last_heartbeat_at)
6-
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at}")
7-
end
8-
end
9-
104
class Process
115
module Prunable
126
extend ActiveSupport::Concern
@@ -28,7 +22,7 @@ def prune
2822
end
2923

3024
def prune
31-
error = ProcessPrunedError.new(last_heartbeat_at)
25+
error = Processes::ProcessPrunedError.new(last_heartbeat_at)
3226
fail_all_claimed_executions_with(error)
3327

3428
deregister(pruned: true)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module SolidQueue
4+
module Processes
5+
class ProcessExitError < RuntimeError
6+
def initialize(status)
7+
message = case
8+
when status.exitstatus.present? then "Process pid=#{status.pid} exited with status #{status. exitstatus}"
9+
when status.signaled? then "Process pid=#{status.pid} received unhandled signal #{status. termsig}"
10+
else "Process pid=#{status.pid} exited unexpectedly"
11+
end
12+
13+
super(message)
14+
end
15+
end
16+
end
17+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module SolidQueue
2+
module Processes
3+
class ProcessMissingError < RuntimeError
4+
def initialize
5+
super("The process that was running this job no longer exists")
6+
end
7+
end
8+
end
9+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module SolidQueue
4+
module Processes
5+
class ProcessPrunedError < RuntimeError
6+
def initialize(last_heartbeat_at)
7+
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at}")
8+
end
9+
end
10+
end
11+
end

lib/solid_queue/supervisor/fork_supervisor.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
# frozen_string_literal: true
22

33
module SolidQueue
4-
class ProcessExitError < RuntimeError
5-
def initialize(status)
6-
message = case
7-
when status.exitstatus.present? then "Process pid=#{status.pid} exited with status #{status.exitstatus}"
8-
when status.signaled? then "Process pid=#{status.pid} received unhandled signal #{status.termsig}"
9-
else "Process pid=#{status.pid} exited unexpectedly"
10-
end
11-
12-
super(message)
13-
end
14-
end
15-
164
class Supervisor::ForkSupervisor < Supervisor
175
include Signals, Pidfiled
186

@@ -126,7 +114,7 @@ def replace_fork(pid, status)
126114

127115
def handle_claimed_jobs_by(terminated_fork, status)
128116
if registered_process = process.supervisees.find_by(name: terminated_fork.name)
129-
error = ProcessExitError.new(status)
117+
error = Processes::ProcessExitError.new(status)
130118
registered_process.fail_all_claimed_executions_with(error)
131119
end
132120
end

lib/solid_queue/supervisor/maintenance.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
module SolidQueue
2-
class ProcessMissingError < RuntimeError
3-
def initialize
4-
super("The process that was running this job no longer exists")
5-
end
6-
end
7-
82
module Supervisor::Maintenance
93
extend ActiveSupport::Concern
104

@@ -35,7 +29,7 @@ def prune_dead_processes
3529

3630
def fail_orphaned_executions
3731
wrap_in_app_executor do
38-
ClaimedExecution.orphaned.fail_all_with(ProcessMissingError.new)
32+
ClaimedExecution.orphaned.fail_all_with(Processes::ProcessMissingError.new)
3933
end
4034
end
4135
end

0 commit comments

Comments
 (0)