Skip to content

Conversation

@fbogsany
Copy link
Member

@fbogsany fbogsany commented Jun 9, 2016

This adds a Middleware.saviour hook to allow overriding the save mechanism. In our case, we want to push the StackProf.results to Kafka.

r: @shivnagarajan

filename ||= "stackprof-#{results[:mode]}-#{Process.pid}-#{Time.now.to_i}.dump"
File.open(File.join(Middleware.path, filename), 'wb') do |f|
f.write Marshal.dump(results)
if saviour.respond_to?(:call)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just assume saviour is callable if non-nil, so if saviour here.

@shivnagarajan
Copy link

👍 for the name saviour, for starters.

proc_called = false
env_set = nil
results_received = nil
middleware = StackProf::Middleware.new(proc {|env| proc_called = true}, enabled: Proc.new{ [true, 'foo'] }, saviour: Proc.new{ |env, results| env_set = env['FOO'] ; results_received = results[:mode] }, save_every: 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG - can we split this line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can we call proc {|arg| ... } vs. Proc.new {|arg| ...}?

proc_called = false
env_set = nil
results_received = nil
enable_proc = Proc.new{ [true, 'foo'] }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_proc = proc{ [true, 'foo'] }?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I want to just replace all Proc.new calls with proc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better: use lambda

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

Successfully merging this pull request may close these issues.

4 participants