zorbash / opus

A framework for pluggable business logic components
MIT License
354 stars 21 forks source link

Conditional link #18

Closed churcho closed 5 years ago

churcho commented 5 years ago

Is it good practice to pipe a pipeline into another from within a stage? Some sort of conditional link.

My fix right now involves piping the results of one pipeline into another and checking a condition in the second stages first step and either returning pipeline or continuing with the steps.

zorbash commented 5 years ago

@churcho Can you provide a code example of what you're trying to do?

churcho commented 5 years ago

Will see if I can create a gist shortly.

It goes something like this: Create Account and set default parameters If account is admin |> Run stages for setting up admin accounts and sending alerts

If account is client |> Run stages for setting up client including sending welcome mail and sms

The account type status stages/steps are a host of like 4-6 operations so I have abstracted into separate pipelines.

I was wondering if it's possible to do something like link AdminPipeline if: :is_admin_account?

zorbash commented 5 years ago

Pipeline links can be conditional, see for example:

defmodule CreateUserPipeline
  use Opus.Pipeline

  step :do_something
  step :do_something_else
  link AdminPipeline, if: :is_admin?
end

Alternatively you can use the skip/2 macro:

defmodule CreateUserPipeline
  use Opus.Pipeline

  step :do_something
  step :do_something_else
  link AdminPipeline
end
defmodule AdminPipeline
  use Opus.Pipeline

  skip :ensure_admin, unless: :is_admin?
end
churcho commented 5 years ago

That's exactly what I was looking for.