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?

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

  • What exactly do you mean?

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

    so state: waiting for status transitions to auth declined

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

    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

    as currently commands are executed before conditions

  • UKGT7RC7P
    UKGT7RC7P 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

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

    but in these cases there is no "else"

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

    as failure is not expected (no external systems involved)

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

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

  • UKHD8KTMF
    UKHD8KTMF 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

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

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

  • UKGT7RC7P
    UKGT7RC7P 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

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

    auth suspend email send fail

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

    retry auth suspend email etc

  • UKGT7RC7P
    UKGT7RC7P 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

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

    i think that just moves the complexity to another file?

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

    so this is what I am going with now:

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

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

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

    or any other approach?

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

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

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

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - 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.

  • UKU1E0ENB
    UKU1E0ENB Posts: 34 πŸ§‘πŸ»β€πŸš€ - 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.

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

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

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

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

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

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

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

    it's the same as running one or multiple commands

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

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