Skip to content
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

[Delayed Job] Runs UPDATE on read-only slave shard #241

Closed
edbond opened this issue May 1, 2014 · 2 comments
Closed

[Delayed Job] Runs UPDATE on read-only slave shard #241

edbond opened this issue May 1, 2014 · 2 comments

Comments

@edbond
Copy link

edbond commented May 1, 2014

2014-05-01 08:43:17.329 [DEBUG] PG::ReadOnlySqlTransaction: ERROR:  cannot execute UPDATE in a read-only transaction
: UPDATE "delayed_jobs" SET locked_at = '2014-05-01 12:43:17.325919', locked_by = 'delayed_job.0 host:host.net pid:24847' WHERE id IN (SELECT  id FROM "delayed_jobs"  WHERE "delayed_jobs"."queue" IN ('queue_0') AND ((run_at <= '2014-05-01 12:43:17.324622' AND (locked_at IS NULL OR locked_at < '2014-05-01 09:43:17.324663') OR locked_by = 'delayed_job.0 host:host.net pid:24847') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING * (pid:24847)

Should it run on master?

@edbond
Copy link
Author

edbond commented May 1, 2014

@edbond
Copy link
Author

edbond commented May 1, 2014

Here is my hack to run reserve method on master shard

module Delayed
  module Backend
    module ActiveRecord
      class Job < ::ActiveRecord::Base
        class << self
          alias_method :reserve_without_octopus, :reserve

          def reserve(worker, max_run_time = Worker.max_run_time)
            Octopus.using(:master) do
              reserve_without_octopus(worker, max_run_time)
            end
          end
        end
      end
    end
  end
end

@edbond edbond closed this as completed May 1, 2014
@edbond edbond changed the title Runs UPDATE on read-only slave shard [Delayed Job] Runs UPDATE on read-only slave shard May 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant