Calling Developers!
We are reenergizing our code contribution process! Learn More

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?

Options
UKGT7RC7P
UKGT7RC7P 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?

«1

Comments

  • Unknown
    Options

    What exactly do you mean?

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    so state: waiting for status transitions to auth declined

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    as currently commands are executed before conditions

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • Unknown
    Options

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

  • Unknown
    Options

    and what exactly failed in case

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    but in these cases there is no "else"

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    as failure is not expected (no external systems involved)

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    edited June 2020
    Options

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

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 🧑🏻‍🚀 - Cadet
    Options

    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

  • UKHD8KTMF
    UKHD8KTMF Posts: 393 🧑🏻‍🚀 - Cadet
    Options

    failure is not expected -> famous last words 😄

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    auth suspend email send fail

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    retry auth suspend email etc

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    technically it makes sense, but practically it's hard

  • Unknown
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    i think that just moves the complexity to another file?

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    so this is what I am going with now:

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    or any other approach?

  • Unknown
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    edited June 2020
    Options

    um, that makes more sense I think 👍

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 🧑🏻‍🚀 - Cadet
    Options

    @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.

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 🧑🏻‍🚀 - Cadet
    Options

    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.

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 🧑🏻‍🚀 - Cadet
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

    it's the same as running one or multiple commands

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 🧑🏻‍🚀 - Cadet
    Options

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