What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Would it be a nice feature in the state machine to have pre and post (condition) commands?

Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
edited June 2020 in Slack General

Would it be a nice feature in the state machine to have pre and post (condition) commands?

Welcome!

It looks like you're new here. Sign in or register to get started.
Β«1

Comments

  • What exactly do you mean?

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    so state: waiting for status transitions to auth declined

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    it would be nice if I could execute a command (send email) after the condition for that transition is true

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    as currently commands are executed before conditions

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    the "solution" is to add an intermediate state, but the state machine can become bloated

  • Agree, and on other hand it’s clearly understandable where item currently is

  • and what exactly failed in case

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    but in these cases there is no "else"

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    as failure is not expected (no external systems involved)

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited June 2020

    Other state machine libraries support pre/post events (e.g. the one used Sylius)

  • Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    isn't pre/post event just a transition that is not explicit? In theory you can hide email sending into the condition but I would not recommend it

  • Posts: 393 πŸ§‘πŸ»β€πŸš€ - Cadet

    failure is not expected -> famous last words πŸ˜„

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    but in this case I would add about 6 states for sending emails, and the transition woul dbe to auth suspened email sent

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    auth suspend email send fail

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    retry auth suspend email etc

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    technically it makes sense, but practically it's hard

  • You can put it into subprocess to separate some functionality like email sending

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    i think that just moves the complexity to another file?

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    so this is what I am going with now:

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    sending declined email is not a good state name, maybe ready to send declined email?

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    or any other approach?

  • In my opinion it should be waiting for auth status -> auth declined -> order declined email sent

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited June 2020

    um, that makes more sense I think πŸ‘

  • Posts: 33 πŸ§‘πŸ»β€πŸš€ - Cadet

    @UKGT7RC7P In an early version of the state machine we had something similar to this. The problem is that whenever you run logic, something can fail und you end up somewhere between the states. That’s why I think it’s a better practice to run only one command per transition.

  • Posts: 33 πŸ§‘πŸ»β€πŸš€ - Cadet

    The official solution is to add a state as you described already. We had very big state machines in the past and when you use sub-processes it doesn’t become chaotic.

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    that can still be the case now though - commands can fail for any unexpected reason

  • Posts: 33 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes and then you end up in the last state before this transition

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    and unless you are highly defensive (failure condition, catching all exceptions) and have a failure state for each command

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    it's the same as running one or multiple commands

  • Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    (and arguably you can "trust" some commands which run within the system)

Welcome!

It looks like you're new here. Sign in or register to get started.