Nebo15 / sage

A dependency-free tool to run distributed transactions in Elixir, inspired by Sagas pattern.
MIT License
912 stars 40 forks source link

Allows users to pass in their own Supervisor for async steps #77

Closed Adzz closed 1 year ago

Adzz commented 1 year ago

Imagine an app called Blog that uses Sage.

Currently Sage allows async steps that spin up a task supervised under Sage.AsyncTransactionSupervisor. Because Sage is a dep of Blog, on shutdown Blog will shutdown before Sage does.

That means if an async step interacts with a process under Blog's supervision tree and you are using some sort of rolling deploy you can enter the following scenario:

  1. Blog starts async task
  2. Sage starts doing that task
  3. Blog shuts down
  4. Sage tries to interact with a process in Blog and can't - so it crashes / errors.

Possible Solutions

  1. Make Sage a library and allow users to start it themselves?
  2. Allow the user to pass in their own supervisor under which it can start the async steps.

This PR does 2.

ulissesalmeida commented 1 year ago

That's a pretty good idea. We should let caller specify which task supervisor the task should run under.

AndrewDryga commented 1 year ago

Hello @Adzz, I love the change.

I think the only things left are tests and adding documentation to functions explaining how we can override the default supervisor.

Adzz commented 1 year ago

Great stuff I'll add that now.

Adzz commented 1 year ago

@AndrewDryga I have added a test and some docs, please let me know if you have any suggestions.

AndrewDryga commented 1 year ago

@Adzz don't worry about docs formatting, LGTM. I'll slightly edit them and release a new version. Thank you ❤️

Adzz commented 1 year ago

Sounds good thanks for the quick feedback!