Class: ThriftRack::Atom

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift_rack/atom.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Atom

Returns a new instance of Atom.



4
5
6
# File 'lib/thrift_rack/atom.rb', line 4

def initialize(app)
  @app = app
end

Class Attribute Details

.redisObject

Returns the value of attribute redis.



23
24
25
# File 'lib/thrift_rack/atom.rb', line 23

def redis
  @redis
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/thrift_rack/atom.rb', line 8

def call(env)
  req = Rack::Request.new(env)
  rpc_id = req.env["HTTP_X_RPC_ID"]
  if rpc_id
    if ThriftRack::Atom.redis.set("thrift_request:#{rpc_id}", true, nx: true, ex: 600)
      @app.call(env)
    else
      [409, {}, ["RPC Request Processed"]]
    end
  else
    @app.call(env)
  end
end