Replies: 6 comments 1 reply
-
Hi there, any news so far? It's a bit blocker for us. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
Hey @nebur395, Thanks for reaching out! I have done some digging into this problem and it seems at its core this is a confusion of
"Step1": {
"Next": "Choice",
...
},
"Choice": {
"Choices": [{
"CONDITION": "RESULT",
"Next": "Step1"
}],
"Default": "Step2"
},
"Step2": {
...
} whereas ASL with Please let me know if you need more info on this! 😸 😷 |
Beta Was this translation helpful? Give feedback.
-
Good morning! Thanks for the reply! :) Maybe I didn't make myself clear. I understand
I don't have in this use case an else clause, (which would be the // In a real scenario this would be a list of steps, not just one
const setupStep1Chain = () => Chain.start(new LambdaInvoke('Step 1'));
const waitUntilStep1HasFinished = () => {
const checkStep1HasFinished = new LambdaInvoke('Check step 1 status');
const waitAndCheck = new Wait('Wait X').next(checkStep1HasFinished);
const step2 = new LambdaInvoke('Step 2');
const step3 = new LambdaInvoke('Step 3');
const step1Choice = new Choice('Has step 1 finished?');
return Chain.start(checkStep1HasFinished)
.next(
step1Choice.
when('No', waitAndCheck)
.otherwise(step2)
);
};
const setupStateMachine = () =>
new StateMachine({
definition: Chain
// You can imagine all these methods, as constructs in different files or workspaces or repos
// instead a simple function in the same file. This is just for make it simpler
.start(setupStep1Chain())
.next(waitUntilStep1HasFinished())
// ... (a list of more chainable next steps or chains)
.next(new Succeed('Done'));
}); This will throw this error: // In a real scenario this would be a list of steps, not just one
const setupStep1Chain = () => Chain.start(new LambdaInvoke('Step 1'));
const waitUntilStep1HasFinished = () => {
const checkStep1HasFinished = new LambdaInvoke('Check step 1 status');
const waitAndCheck = new Wait('Wait X').next(checkStep1HasFinished);
const step2 = new LambdaInvoke('Step 2');
const step3 = new LambdaInvoke('Step 3');
const step1Choice = new Choice('Has step 1 finished?');
return Chain.start(checkStep1HasFinished)
.next(
step1Choice.
when('No', waitAndCheck)
.otherwise(step2)
.afterwards()
);
};
const setupStateMachine = () =>
new StateMachine({
definition: Chain
// You can imagine all these methods, as constructs in different files or workspaces or repos
// instead a simple function in the same file. This is just for make it simpler
.start(setupStep1Chain())
.next(waitUntilStep1HasFinished())
// ... (a list of more chainable next steps or chains)
.next(new Succeed('Done'));
}); This should be what I was looking for I guess. In order to follow the flow out of the conditional statements. However, since one of the flows is a loop, I will get this error: So I wonder if there is any possibility to give the flow control back to the main thread, cause I would wanna reach something similar to this: const setupStep1Chain = () => Chain.start(new LambdaInvoke('Step 1'));
const waitUntilStep1HasFinished = () => {
const checkStep1HasFinished = new LambdaInvoke('Check step 1 status');
const waitAndCheck = new Wait('Wait X').next(checkStep1HasFinished);
const step1Choice = new Choice('Has step 1 finished?');
return Chain.start(checkStep1HasFinished)
.next(step1Choice.when('No', waitAndCheck));
};
const setupStateMachine = () =>
new StateMachine({
definition: Chain
.start(setupStep1Chain())
.next(waitUntilStep1HasFinished())
// ... (and I would want to continue the flow here!! :octocat:
.next(new Succeed('Done'));
}); I hope I made myself clearer now :) |
Beta Was this translation helpful? Give feedback.
-
I found this issue because of the same problem. I understand What I expected, using the example from above: Chain
.start(setupStep1Chain())
.next(waitUntilStep1HasFinished())
.next(new Pass('Done')); what I have to do: Chain
.start(setupStep1Chain())
.next(waitUntilStep1HasFinished(new Chain
.start(new Pass('Done'))
.next(...)
))
const waitUntilStep1HasFinished = (nextStep) => {
const wait = new Wait()
return Chain
.start(wait)
.next(
new Choice()
.when(Condition.something(), wait)
.otherwise(nextStep)
)
} so each Chain is making a nested structure, while it could be flattened out. |
Beta Was this translation helpful? Give feedback.
-
I have same problem. I found Parallel is effective for this case.
|
Beta Was this translation helpful? Give feedback.
-
I had the same problem, managed to solve it thanks to previous comments and by using Example: const step1 = new sfn.Pass(this, 'step1')
const step2 = new sfn.Pass(this, 'step2')
const step1Choice = new sfn.Choice(this, 'check?')
.when(sfn.Condition.booleanEquals('$.foo', true), step2, { comment: 'finished!' })
.otherwise(new sfn.Wait(this, 'wait', { time: sfn.WaitTime.duration(cdk.Duration.seconds(15)) }).next(step1))
.afterwards()
//const step1Chain = sfn.Chain.start(step1).next(step1Choice) // Instead of this, do:
const step1Chain = sfn.Chain.sequence(step1.next(step1Choice), step2)
const done = new sfn.Pass(this, 'done')
const chain = step1Chain.next(done) |
Beta Was this translation helpful? Give feedback.
-
❓ General Issue
The Question
I would want to use a Chain-Choice flow to make a loop within a step function. Besides that, I would like to be able to follow the main chain at root level, not at condition level. I've tried to use
afterwards
method since I thought this was for implemented following this purpose but it doesn't seem to work or I'm missing some implementation details.Context/Background
I'm splitting the state machine in several constructs for readability and encapsulation reasons. Simplifying the use case it would look something like this (notice it's written in TS and it's just pseudo-code):
This is how I understood the method
afterwards()
should look like. However if I follow this approach, I just get this error:And if I remove the
.afterwards()
method, I would get this other error:I tried different approaches in the Choice step such as using
.otherwise()
and intermediatePass
state... and a lot of this, but nothing seems to work. Of course, I can follow the flow in the conditional statement, something like this:However, this looks for me a bit weird for some architectural patterns, since you have to make
waitUntilStep1HasFinished()
method aware of the next chainable logic and as the author (of the issue I'm going to link at the end) said, you really decrease the readability of the code defining the state machine, having to read it by inspecting each Choice.Is there any workaround to make this? Am I missing something in the afterwards feature?
Please, find just below a visual representation of what I would like to achieve with the pseudo-code I've just posted
Thanks a lot!
Environment
Other information
This issue is highly related with this one, it was closed without a response though
Beta Was this translation helpful? Give feedback.
All reactions