Skip to content

Commit

Permalink
Move error classes to their own files so they can be loaded by Zeitwerk
Browse files Browse the repository at this point in the history
Closes #313
  • Loading branch information
rosa committed Aug 30, 2024
1 parent e580fe7 commit 46f66de
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
8 changes: 1 addition & 7 deletions app/models/solid_queue/process/prunable.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# frozen_string_literal: true

module SolidQueue
class ProcessPrunedError < RuntimeError
def initialize(last_heartbeat_at)
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at}")
end
end

class Process
module Prunable
extend ActiveSupport::Concern
Expand All @@ -28,7 +22,7 @@ def prune
end

def prune
error = ProcessPrunedError.new(last_heartbeat_at)
error = Processes::ProcessPrunedError.new(last_heartbeat_at)
fail_all_claimed_executions_with(error)

deregister(pruned: true)
Expand Down
17 changes: 17 additions & 0 deletions lib/solid_queue/processes/process_exit_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module SolidQueue
module Processes
class ProcessExitError < RuntimeError
def initialize(status)
message = case
when status.exitstatus.present? then "Process pid=#{status.pid} exited with status #{status. exitstatus}"
when status.signaled? then "Process pid=#{status.pid} received unhandled signal #{status. termsig}"
else "Process pid=#{status.pid} exited unexpectedly"
end

super(message)
end
end
end
end
9 changes: 9 additions & 0 deletions lib/solid_queue/processes/process_missing_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module SolidQueue
module Processes
class ProcessMissingError < RuntimeError
def initialize
super("The process that was running this job no longer exists")
end
end
end
end
11 changes: 11 additions & 0 deletions lib/solid_queue/processes/process_pruned_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module SolidQueue
module Processes
class ProcessPrunedError < RuntimeError
def initialize(last_heartbeat_at)
super("Process was found dead and pruned (last heartbeat at: #{last_heartbeat_at}")
end
end
end
end
14 changes: 1 addition & 13 deletions lib/solid_queue/supervisor/fork_supervisor.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
# frozen_string_literal: true

module SolidQueue
class ProcessExitError < RuntimeError
def initialize(status)
message = case
when status.exitstatus.present? then "Process pid=#{status.pid} exited with status #{status.exitstatus}"
when status.signaled? then "Process pid=#{status.pid} received unhandled signal #{status.termsig}"
else "Process pid=#{status.pid} exited unexpectedly"
end

super(message)
end
end

class Supervisor::ForkSupervisor < Supervisor
include Signals, Pidfiled

Expand Down Expand Up @@ -126,7 +114,7 @@ def replace_fork(pid, status)

def handle_claimed_jobs_by(terminated_fork, status)
if registered_process = process.supervisees.find_by(name: terminated_fork.name)
error = ProcessExitError.new(status)
error = Processes::ProcessExitError.new(status)
registered_process.fail_all_claimed_executions_with(error)
end
end
Expand Down
8 changes: 1 addition & 7 deletions lib/solid_queue/supervisor/maintenance.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
module SolidQueue
class ProcessMissingError < RuntimeError
def initialize
super("The process that was running this job no longer exists")
end
end

module Supervisor::Maintenance
extend ActiveSupport::Concern

Expand Down Expand Up @@ -35,7 +29,7 @@ def prune_dead_processes

def fail_orphaned_executions
wrap_in_app_executor do
ClaimedExecution.orphaned.fail_all_with(ProcessMissingError.new)
ClaimedExecution.orphaned.fail_all_with(Processes::ProcessMissingError.new)
end
end
end
Expand Down

0 comments on commit 46f66de

Please sign in to comment.