Skip to content

Move error classes to their own files so they can be loaded by Zeitwerk #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading