anycable / graphql-anycable

A drop-in replacement for GraphQL ActionCable subscriptions. Works with AnyCable.
MIT License
107 stars 16 forks source link

Extract the stale subscription cleaning in library code #11

Closed gsamokovarov closed 4 years ago

gsamokovarov commented 4 years ago

At Receipt Bank, we're using GraphQL Subscriptions with graphql-anycable, but we cannot easily execute rake tasks as periodical jobs and we had to copy-paste the rake task code into a job we can call. It would be way easier for setups like ours if we can invoke the cleaning process through plain Ruby code. This is where GraphQL::Anycable::Cleaner.clean comes in. If we can execute this in our periodic job, everything will be way easier.

Another aspect that is problematic for us is the configuration that is currently limited only to environment variables, as we're not keeping a "global" anyway config object reference, but instantiating it when needed and this supports configuration only through ENV variables, as far as I understand Anyway.

Having a global GraphQL::Anyway.config (and the syntax sugar of GraphQL::Anyway.configure) will help us avoid monkey patches we have to graphql-anycable to share a global config for subscription_expiration_seconds we set through our custom configuration management solution.

What do you think about those changes? I haven't figured out a simple way to unit-test the changes, but have tested them against a fork of our app and seem to work.

palkan commented 4 years ago

Hey @gsamokovarov!

Another aspect that is problematic for us is the configuration that is currently limited only to environment variables, as we're not keeping a "global" anyway config object reference, but instantiating it when needed and this supports configuration only through ENV variables, as far as I understand Anyway.

Anyway Config can load data from YAML configs. For example:

# config/graphql_anycable.yml
production:
  subscription_expiration_seconds: 300
  use_redis_object_on_cleanup: true  

And I think, that should be the preferred option (not ENV) since these values are likely to be configured once and contain no sensitive information (so, it's okay to store them in the repo). @Envek WDYT? Maybe, we should update the readme or at least add a note about YAML-based configuration.

And I'm 👍 for extracting Cleaner into a module.

gsamokovarov commented 4 years ago

Thanks, Vlad! Didn't know about the YML config files support in anyway.

Envek commented 4 years ago

Released as 0.4.0, added a note to README about ways of configuring the gem.

Thank you very much!