Sha256: f761b9d025fc50c858fbbec4fce3b9ff51861927d59056a5a97146688df95dc4

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

# Saves a block for execution after the HTTP response has been sent to the user.
# When the block is executed, it connects to the database before executing the code.
# This is good for doing things that might take a while and don't have to be done before
# the response is sent, and don't need retries (in which case, it might be better to use a SuckerPunch Job).
#
# This leverages a feature of Puma which I'm not sure is meant to be public or not.
# There are serveral mentions of it on the internet, so I assume it's ok to use it.
# Puma itself uses the rack.after_reply for http request logging.
#
# https://github.com/search?q=repo%3Apuma%2Fpuma%20rack.after_reply&type=code

module PactBroker
  module Async
    class AfterReply
      def initialize(rack_env)
        @rack_env = rack_env
        @database_connector = rack_env.fetch("pactbroker.database_connector")
      end

      def execute(&block)
        dc = @database_connector
        @rack_env["rack.after_reply"] << lambda {
          dc.call do
            block.call
          end
        }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pact_broker-2.114.0 lib/pact_broker/async/after_reply.rb
pact_broker-2.113.2 lib/pact_broker/async/after_reply.rb
pact_broker-2.113.1 lib/pact_broker/async/after_reply.rb
pact_broker-2.113.0 lib/pact_broker/async/after_reply.rb
pact_broker-2.112.0 lib/pact_broker/async/after_reply.rb
pact_broker-2.111.0 lib/pact_broker/async/after_reply.rb
pact_broker-2.109.1 lib/pact_broker/async/after_reply.rb
pact_broker-2.109.0 lib/pact_broker/async/after_reply.rb
pact_broker-2.108.0 lib/pact_broker/async/after_reply.rb