ruby-protobuf / protobuf

A pure ruby implementation of Google's Protocol Buffers
https://github.com/ruby-protobuf
MIT License
463 stars 101 forks source link

Server before/afer startup callbacks #404

Closed film42 closed 5 years ago

film42 commented 5 years ago

We currently have the ability to subscribe to callbacks via:

ActiveSupport::Notifications.subscribe('after_server_bind') { ... }

This proposes 2 changes:

  1. Add a new before_server_bind event that is published before a runner's run method is called via the CLI.
  2. A new helper method for {before,after}_server_bind on the Protobuf module.

Example:

Protobuf.before_server_bind do
  eager_load_some_data_only_when_server_starts!
end

Protobuf.after_server_bind do
  report_server_online!
end

I also considered adding these to the Protobuf::Rpc::Server module since it's more specific to the use-case, but felt like the root Protobuf was "good enough" so please let me know if you have a strong preference either way.

cc @liveh2o @abrandoned

liveh2o commented 5 years ago

Not sure what’s up with the build failing.