Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Enhance WAIT task to support time-based wait scenarios #2986

Merged
merged 14 commits into from
May 31, 2022

Conversation

v1r3n
Copy link
Contributor

@v1r3n v1r3n commented May 12, 2022

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes (Please run ./gradlew generateLock saveLock to refresh dependencies)
  • WHOSUSING.md
  • Other (please describe):

Changes in this PR

Enhance wait task to be able to wait for a specific amount of time.
One commonly asked use case is to allow a task to wait for specific duration of time (e.g. 15 minutes) or until certain date/time (Dec 31, 2022).

These updates allows users to configure Wait tasks with two inputs:

Wait For time duration

Format duration as "XhYmZs"

{
  "type": "WAIT",
   "inputParameters": {
     "duration": "10m20s",
   }
}

Wait until specific date/time

Specify the date as one of the formats:

  1. "yyyy-MM-dd HH:mm",
  2. "yyyy-MM-dd HH:mm z",
  3. "yyyy-MM-dd"
{
  "type": "WAIT",
   "inputParameters": {
     "until": "2022-12-31 11:59",
   }
}

String until =
Optional.ofNullable(task.getInputData().get(UNTIL_INPUT)).orElse("").toString();

if (Strings.isNotBlank(duration) && Strings.isNotBlank(until)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings is from log4j. Please use StringUtils from commons-lang3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

if (Strings.isNotBlank(duration) && Strings.isNotBlank(until)) {
task.setReasonForIncompletion(
"Both 'duration' and 'until' specified. Please provide only one input");
task.setStatus(FAILED);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the status be FAILED_WITH_TERMINAL_ERROR? This error is not recoverable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

String until =
Optional.ofNullable(task.getInputData().get(UNTIL_INPUT)).orElse("").toString();

if (Strings.isNotBlank(duration) && Strings.isNotBlank(until)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task validations are typically done when the workflow is registered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this as part of workflow creation.

} else if (Strings.isNotBlank(until)) {
try {
Date expiryDate = parseDate(until);
System.out.println("expiryDate: " + expiryDate);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove SOP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

} catch (ParseException parseException) {
task.setReasonForIncompletion(
"Invalid/Unsupported Wait Until format. Provided: " + until);
task.setStatus(FAILED);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could also be FAILED_WITH_TERMINAL_ERROR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

if (Strings.isNotBlank(duration)) {

Duration timeDuration = parseDuration(duration);
task.getOutputData()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding the timeout to the output data, we suggest that its added as a field to the TaskModel. We think its a better fit because,

  1. TaskModel is internal only and fields in it are not exposed to the user. Adding it to outputData makes the timeout field part of the task contract.
  2. We have plans to create custom TaskModels which only contain fields for a particular task type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use TaskModel

task.getOutputData()
.put(TIMEOUT, System.currentTimeMillis() + (timeDuration.getSeconds() * 1000));
long seconds = timeDuration.getSeconds();
task.setCallbackAfterSeconds(seconds);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callbackAfterSeconds is moot since WAIT is a synchronous task and is not added to a queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated and removed.

@aravindanr
Copy link
Collaborator

@v1r3n can you update the documentation section for WAIT task? cc: @dougsillars

@apanicker-nflx apanicker-nflx added the type: feature New feature label May 16, 2022
v1r3n added 3 commits May 18, 2022 23:00
1.  Added validations at the time of workflow creation
2. Using commons lang StringUtils
3. Using TaskModel to store timeout
4. Update documentation
# SDKs for other languages

Language specific client SDKs are maintained at a dedicated [conductor-sdk](https://github.com/conductor-sdk) repository.
All the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

public Wait() {
super(TASK_TYPE_WAIT);
}

public static Duration parseDuration(String text) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving these static methods to Utils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.netflix.conductor.utils;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a Utils package here. Can you move this class under the same package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@apanicker-nflx apanicker-nflx changed the title Wait improvements Enhance WAIT task to support Timed-based wait scenarios May 31, 2022
@apanicker-nflx apanicker-nflx changed the title Enhance WAIT task to support Timed-based wait scenarios Enhance WAIT task to support timed-based wait scenarios May 31, 2022
@apanicker-nflx apanicker-nflx changed the title Enhance WAIT task to support timed-based wait scenarios Enhance WAIT task to support time-based wait scenarios May 31, 2022
@apanicker-nflx apanicker-nflx merged commit 3b5aed1 into Netflix:main May 31, 2022
@v1r3n v1r3n deleted the wait_improvements branch June 15, 2022 06:28
pmchung pushed a commit to routific/conductor that referenced this pull request Sep 6, 2023
* Update Wait.java

* Add support for waiting for time duration or until a specific date/time

* add unit tests and SDK methods

* formatting

* Remove Guava dependency

* Fix formatting

* Wait task updates

1.  Added validations at the time of workflow creation
2. Using commons lang StringUtils
3. Using TaskModel to store timeout
4. Update documentation

* remove callbackafter

* add the break

* Fix readme

* Move the date parsing to a util class

* move DateTimeUtils to the common utils package
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants