steveklabnik / request_store

Per-request global storage for Rack.
https://github.com/steveklabnik/request_store
MIT License
1.47k stars 87 forks source link

Will this work with Serverless? #76

Open prcongithub opened 3 years ago

prcongithub commented 3 years ago

We are using AWS Lambda to run our Ruby on Rails based App. We use SQS to trigger lambda function to process background jobs.

Here is how the handler looks like:

def handler(event:, context:)
  begin
      event = event.with_indifferent_access
      event[:Records].each do |record|
        begin
          RequestStore.store[:seller] = record[:seller]
          AsyncHandler.new(record).handle
        rescue Exception => e
          mail_exception(e, record)
        end  
      end
  rescue Exception => e
    mail_exception(e, event)
  end
end

We are facing this weird issue with batch processing of AWS SQS queue where in the RequestStore is getting cleared in the middle of processing of batch of records.

Somewhere inside the AsyncHandler the RequestStore[:seller] becomes nil.

Any ideas here?

steveklabnik commented 3 years ago

I personally have no idea.