Skip to content

Get rid of obsolete Sleep state and replace it with an action #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdavernas opened this issue Sep 21, 2022 · 22 comments · Fixed by #833
Closed

Get rid of obsolete Sleep state and replace it with an action #686

cdavernas opened this issue Sep 21, 2022 · 22 comments · Fixed by #833
Assignees
Labels
area: spec Changes in the Specification change: feature New feature or request. Impacts in a minor version change
Milestone

Comments

@cdavernas
Copy link
Member

What would you like to be added:

Get rid of obsolete Sleep state and replace it with an action. The state has little to no use IMO, especially since the addition of the sleepBefore/sleepAfter properties to the actionDef.

What I propose is to remove the sleepBefore/after properties and the sleep state, and replace them with an action of type sleep or delay.

...
actions:
  name: Sleep
  delay: PT30M
...

Why is this needed:

What the sleep state achieves can be done using the sleepBefore/after properties, which IMO are very wierd in the context of an action. As a matter of fact, it should not be the responsibility or in the domain of the action to delay its own processing or its return. A better way is IMO to achieve that feature with an EXPLICIT action, which will therefore be visible in visualization tools, making the spec more ubiquitous, clean and concise.

@cdavernas cdavernas added change: feature New feature or request. Impacts in a minor version change area: spec Changes in the Specification schema labels Sep 21, 2022
@tsurdilo
Copy link
Contributor

Currently actions require one of the "refs" to point to a function definition: https://github.com/serverlessworkflow/specification/blob/main/schema/workflow.json#L486
How would you suggest this for sleep, to have a "sleep" function type maybe but that seems kinda not natural. Let me know please.

@cdavernas
Copy link
Member Author

@tsurdilo I'm nowhere recommending putting that as a new function type. I'm recommending putting it as an action type.

So far, we implicitly have 3 action types:

  • Subflow
  • Function
  • Event

I'm recommending adding:

  • Sleep/Delay

@fjtirado
Copy link
Collaborator

Do we have a use case for sleep? Im asking because Ill remove sleeps altogether. We should wait for something, not a random amount of time.

@ricardozanini
Copy link
Member

I'm also curious to hear a use case for sleep.

@fjtirado
Copy link
Collaborator

fjtirado commented Sep 27, 2022

Assuming we have to wait a random amount of time after an action has been executed and before another action is executed, I would add the sleep as an optional (and discouraged) property of the "weak" action itself.
In my opinion, waits are indication of a flaw in the design of a particular action, so lets keep them isolated in the place where they might be used as last resort (which in my opinion is the flawed action)

@tsurdilo
Copy link
Contributor

dont diss sleep so much . it has very valid use its rly important for testing as well as waiting on certain time to trigger actions / continue. it should not be discouraged to be used

@tsurdilo
Copy link
Contributor

sleep in actions are important for testing . in a test you could have a fake action that just returns and use sleep to simulate diff exec times and test timeouts .

@fjtirado
Copy link
Collaborator

yes, but you are testing sleeps associated to actions, isnt it?

@tsurdilo
Copy link
Contributor

no, the before after can be used to simulate action exec time and action timeouts. the sleep state is useful yea to test wf exec timeout and state timeout but also has valid business logic use cases

@cdavernas
Copy link
Member Author

cdavernas commented Sep 27, 2022

@fjtirado IMO, sleep can be usefull, but they should be an action, not an action prop.

Imagine a more real-life scenario than just "emulating" network delay, as explained by @tsurdilo: Long polling on a remote API. You would loop while a condition is true and make sure to wait an explicit amount of time before and/or after the execution of the polling request.

@fjtirado
Copy link
Collaborator

@cdavernas The way I envision that scenario is that the action you use to perform to the polling has the property to wait after it is executed (rather than adding a "fake" action there to wait)

@tsurdilo
Copy link
Contributor

for polling there are couple ways, one is using sleep as described, another is polling via retries and backoff coefficient third is polling inside the action function itself

@tsurdilo
Copy link
Contributor

tsurdilo commented Sep 27, 2022

i think sleep state feels more naturan in some cases than sleep action which ppl associate with actual invocation of things..but can be argued as its preference. only problem is timeouts as for sleep action its bound by action timeout but who knows thats fine

@ricardozanini
Copy link
Member

Okay, I can see us cases for testing, but not for pooling. If you guys wanna go ahead with this, I think an action like what Charles was proposing might have more sense. If I see a workflow definition with sleep without a testing context, I'd assume that's a workaround.

@tsurdilo
Copy link
Contributor

tsurdilo commented Sep 27, 2022

but not for pooling

for polling with sleep state think of simple operationState(perform action)->switchState(check result)->sleepState(sleep for x time)->loop back to operationState
thats how i think you would do it in bpmn too

its a valid use case imo but all i said was you can also poll via action retries too

@ricardozanini
Copy link
Member

That makes sense, but I would implement it differently unless I'd need to directly express the sleep stage in the definition.

Yeah, it makes it a valid use case.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@fjtirado
Copy link
Collaborator

fjtirado commented Mar 4, 2024

@cdavernas As you propose, I think we can remove sleep state and rely on sleep before and after function execution.
I do not think there is a use case to sleep before or after doing nothing.

fjtirado added a commit to fjtirado/specification that referenced this issue Mar 18, 2024
Removing sleep state, as it is redundant with sleep after and before
fjtirado added a commit to fjtirado/specification that referenced this issue Mar 18, 2024
Removing sleep state, as it is redundant with sleep after and before

Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
ricardozanini added a commit that referenced this issue Apr 3, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Progress Tracker Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: spec Changes in the Specification change: feature New feature or request. Impacts in a minor version change
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants