librelist archives

« back to archive

multiple actions in a single state...

multiple actions in a single state...

From:
Justin Steward
Date:
2011-06-21 @ 03:30
Hi,

Just started playing around with lamson, and looks like it should be a
good fit for a couple project I've got going.

What I'm trying to create is a workflow where a post is followed by a
confirmation, HOWEVER, I want someone to be able to send in two,
three, or more posts, and then confirm each post. My first approach of
POSTING and CONFIRMING states, meant that a post needed to be
confirmed before another could be posted.

What is the "right" way to handle these sorts of situations?

The librelist code has a similar situation, unsubscribing/posting, but
the solution there seems inelegant... we have two very different
actions being performed in the one state...

Right now, I've created this monster (admittedly more complex than
strictly necessary, but that's mostly a result of boredom and
tinkering with lamson's internals):

@route("(to)", to=".+")
def POST_OR_CONFIRM(message, to):
    next=None
    for routes in Router.match(to):
        if CONFIRMING in routes[0]:
            next, kwargs = CONFIRMING, routes[1]
        elif POSTING in routes[0]:
            next, kwargs = POSTING, routes[1]
        if next:
            return next(message,**kwargs)


~Justin

Re: [lamson] multiple actions in a single state...

From:
Scott Reynolds
Date:
2011-06-21 @ 15:27
The right way to is to create two handlers, app/handlers/post.py and
app/handlers/confirm.py

(Although I prefer "publish" to "confirm" because "publish" doesn't
clash with confirmation api)

Rationale:
You have found that having one Finite State Machine is not working
because a user cannot be in two states (POSTING or CONFIRMING) at the
same time. Thus you need to have two Finite State Machines and to
create another FSM you create another handler.

On Mon, Jun 20, 2011 at 8:30 PM, Justin Steward <althalus87@gmail.com> wrote:
> Hi,
>
> Just started playing around with lamson, and looks like it should be a
> good fit for a couple project I've got going.
>
> What I'm trying to create is a workflow where a post is followed by a
> confirmation, HOWEVER, I want someone to be able to send in two,
> three, or more posts, and then confirm each post. My first approach of
> POSTING and CONFIRMING states, meant that a post needed to be
> confirmed before another could be posted.
>
> What is the "right" way to handle these sorts of situations?
>
> The librelist code has a similar situation, unsubscribing/posting, but
> the solution there seems inelegant... we have two very different
> actions being performed in the one state...
>
> Right now, I've created this monster (admittedly more complex than
> strictly necessary, but that's mostly a result of boredom and
> tinkering with lamson's internals):
>
> @route("(to)", to=".+")
> def POST_OR_CONFIRM(message, to):
>    next=None
>    for routes in Router.match(to):
>        if CONFIRMING in routes[0]:
>            next, kwargs = CONFIRMING, routes[1]
>        elif POSTING in routes[0]:
>            next, kwargs = POSTING, routes[1]
>        if next:
>            return next(message,**kwargs)
>
>
> ~Justin
>

Re: [lamson] multiple actions in a single state...

From:
Justin Steward
Date:
2011-06-21 @ 23:50
Hi,

On Wed, Jun 22, 2011 at 1:27 AM, Scott Reynolds <sdrreynolds@gmail.com> wrote:
> The right way to is to create two handlers, app/handlers/post.py and
> app/handlers/confirm.py
>
> (Although I prefer "publish" to "confirm" because "publish" doesn't
> clash with confirmation api)
Using confirm in my case is really just the fault of following along
with the examples a little too closely :)

> Rationale:
> You have found that having one Finite State Machine is not working
> because a user cannot be in two states (POSTING or CONFIRMING) at the
> same time. Thus you need to have two Finite State Machines and to
> create another FSM you create another handler.

Hmm, I can see the logic there, just doesn't feel very intuitive to
have two FSMs for what is really two parts of the one action. I got as
far as realising a user can't have more than one state, I guess I'm
just too used to different ways of working to be able to make that
final step towards "add another FSM". A lot of learning to do!

Thanks,
Justin