Open ianks opened 6 years ago
hey, thanks for this issue. I really love this idea and want to see it in 0.3
version.
we can create Hanami::Events::Runner
class which take event object and will start server, but I'm not sure that putting all config information to CLI is a good idea. Also, what we will do if we have more than one events instance in the project?
what we will do if we have more than one events instance in the project?
That's a good question. I wonder if that's a common use case? Currently, I have it configured so a runner is only responsible for a single events instance:
so, we don't have a global state. It's mean that you can create 1+ instance of hanami events and use it. Also, I will be happy to stay with it. We can create runner without global state, just inject event object into constructor:
runner = Hanami::Events::Runner.new(event_object, **options)
runner.start
It will help us use different events instances with different ways (local memory pubsub, persistence pubsub, etc). WDYT?
also, one more thing here: I think we need to use different runners for different types of events. Something like thread runner for memory async and server runner for redis events (like sidekiq).
Not sure but I think we can use one runner with different adapters in thread and in CLI.
Yeah, I think we should decouple events
from the runner. events
should just register the subscribers, while the runner can actually provide the events with an adapter
to actually subscribe to the events.
I think we need to use different runners for different types of events.
Would this mean you would need two runners if you had users.created
and users.deleted
events?
@ianks I created PoC for runner and merged it. Do you have any ideas what we need to do next? From my perspective: middlewares and test it with other adapters.
Also, I checked your runner and events fork. Maybe we need to think about Listener
in the current implementation. But I'm not sure that it's a great idea for PoC now
I have recently had the pleasure of building a Google Cloud Pub/Sub adapter for hanami-events. Overall, the experience was very straightforward and I think hanami-events fits perfecting with the pub/sub model.
One thing I would like to add to hanami-events is:
First-Class Support for Subscribers in Separate Processes
In most production systems, workers/subscribers will need to scale independently of the web process. For example, on Monday we may need to process 10x the events we do on Sunday.
To address the need for independent scaling, I think having a first-class API for a "Runner/Manager" should be provided. By adding this, we can build a general-purpose CLI for running these processes, which will handle low-level details that the adapter should not have to care about (Signal Handlers, health checks, daemonization, etc).
With this CLI, users could simply run
hanami worker run --adapter sqsredis/pubsub/etc
.In order to make this possible, we should begin designing the interface which adapters should implement to provide this functionality. My first (rough) sketch looks something like this:
By abstracting our some conventions, we can create powerful tooling to empower Hanami users (maybe even a pretty dashboard for managing things one day :wink:).
I would love to help make this a reality, so please provide as much feedback as possible!