Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.

Introduce Queued State #10

Merged
merged 7 commits into from
Dec 7, 2016
Merged

Introduce Queued State #10

merged 7 commits into from
Dec 7, 2016

Conversation

rouzwawi
Copy link
Member

@rouzwawi rouzwawi commented Nov 30, 2016

This is mainly a refactor of existing behaviour into a setup that makes it easier to implement further scheduling behaviour.

The change also renames the AWAITING_RETRY state to a more generic QUEUED state.

> STYX_CLI_HOST=localhost:8080 styx ls -c example-component
  WORKFLOW INSTANCE    STATE            LAST EXECUTION ID                               PREVIOUS EXECUTION INFO

example-component bihourly-job
  2016-12-01           QUEUED           styx-run-bc83472a-f4e8-4bab-a86a-070bf6649054   Exit code: 20
  2016-12-02           QUEUED           styx-run-212ef3f0-8ae3-4f56-b969-75319ef93cda   Exit code: 20
  2016-12-03           QUEUED           styx-run-6a03f8de-8b69-42e0-8615-d00371ae5afe   Exit code: 20

@rouzwawi rouzwawi force-pushed the queued branch 8 times, most recently from babac40 to fdebd1c Compare December 4, 2016 16:45
@@ -58,6 +59,11 @@
void receive(Event event) throws IsClosed;

/**
* Get a map of all active {@link WorkflowInstance} states.
*/
ImmutableMap<WorkflowInstance, RunState> activeStates();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ImmutableMap and not just Map? Would anyone think they can mutate the return value of this and somehow that would be persisted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Will replace with just Map

return isAtOrAfter(now, deadline);
}

private boolean isAtOrAfter(Instant now, Instant deadline) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I find this function confusing, I'm not sure which value is at or after compared to the other and isn't this the same as !foo.isAfter(bar)?

@bergman
Copy link
Contributor

bergman commented Dec 6, 2016

LGTM so far but I guess we need to redirect the old events (triggerExec, submit) to this QUEUED state?

@@ -202,7 +157,12 @@ public RunState triggerExecution(WorkflowInstance workflowInstance, String trigg
public RunState created(WorkflowInstance workflowInstance, String executionId, String dockerImage) {
switch (state()) {
case PREPARE:
Copy link
Member

Choose a reason for hiding this comment

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

For clarity we should add // for backwards compatibility comment.


default:
throw illegalTransition("runError");
}
}

@Override
public RunState enqueue(WorkflowInstance workflowInstance) {
Copy link
Member

@fabriziodemaria fabriziodemaria Dec 6, 2016

Choose a reason for hiding this comment

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

Can we use retryAfter instead of introducing a new enqueue event? We would reduce the need for "supporting" deprecated events/transitions.

We could also modify retryAfter to drop the delayMillis, which is not needed anymore with the new Scheduler. The only drawback I see with this approach is that the name retryAfter would be a bit confusing without an explicit delay argument in the constructor.

Also, without an explicit delay in the event (either enqueue or retryAfter), we would lose the possibility to return the expected delay in the CLI events command. Perhaps we could keep retryAfter as is for now, and remove the delayMillis when introducing the info event.

@@ -286,7 +290,11 @@ public RunState retryAfter(WorkflowInstance workflowInstance, long delayMillis)
switch (state()) {
case TERMINATED:
case FAILED:
Copy link
Member

Choose a reason for hiding this comment

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

If we introduce enqueue, the two lines above should include // for backwards compatibility

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the enqueue and dequeue events from this PR, so it's mainly focused on just introducing the QUEUED state.

@@ -212,7 +216,7 @@ public StyxScheduler build() {
scheduleSources,
statsFactory,
executorFactory,
publisherFactory);
publisherFactory, retryUtil);
Copy link
Member

Choose a reason for hiding this comment

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

Should have its own new line :)

final Duration delay = baseDelay.multipliedBy(multiplier);

final String instanceKey = state.workflowInstance().toKey();
LOG.info("{} scheduling retry #{} in {}", instanceKey, state.data().tries(), delay);
Copy link
Member

Choose a reason for hiding this comment

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

Is it intended to leave out this logging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

@@ -298,7 +306,7 @@ public RunState retry(WorkflowInstance workflowInstance) {
switch (state()) {
case TERMINATED: // for backwards compatibility
case FAILED: // for backwards compatibility
case AWAITING_RETRY:
case QUEUED:
Copy link
Member

Choose a reason for hiding this comment

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

// for backwards compatibility

@rouzwawi
Copy link
Member Author

rouzwawi commented Dec 6, 2016

@bergman I've deferred redirecting triggerExecution and submit into QUEUED to se later PR.

@rouzwawi rouzwawi force-pushed the queued branch 3 times, most recently from 5336c0d to e85708e Compare December 6, 2016 17:01
@bergman
Copy link
Contributor

bergman commented Dec 7, 2016

👍

@rouzwawi rouzwawi merged commit 77cc992 into master Dec 7, 2016
@rouzwawi rouzwawi deleted the queued branch December 7, 2016 10:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants