Skip to content

Commit

Permalink
feat(polling): remove polling for wait, manual judgement, and executi…
Browse files Browse the repository at this point in the history
…on window (#1661)
  • Loading branch information
emjburns authored Oct 18, 2017
1 parent f86de36 commit e01058b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.pipeline

import java.time.Duration
import java.util.concurrent.TimeUnit
import com.google.common.annotations.VisibleForTesting
import com.netflix.spinnaker.orca.ExecutionStatus
Expand Down Expand Up @@ -60,8 +61,21 @@ class RestrictExecutionDuringTimeWindow implements StageDefinitionBuilder {
@Value('${tasks.executionWindow.timezone:America/Los_Angeles}')
String timeZoneId

@Override
long getDynamicBackoffPeriod(Duration taskDuration) {
if (taskDuration < Duration.ofMillis(timeout)) {
// wait until timeout is over to poll
return Duration.ofMillis(timeout).toMillis()
} else {
//start polling normally after timeout to account for delays like throttling
return backoffPeriod
}
}

@Override
TaskResult execute(Stage stage) {
stage.getTopLevelTimeout().ifPresent({ timeout = it })

Date now = new Date()
Date scheduledTime
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.pipeline.tasks

import java.time.Duration
import java.util.concurrent.TimeUnit
import com.netflix.spinnaker.orca.RetryableTask
import com.netflix.spinnaker.orca.TaskResult
Expand All @@ -30,14 +31,27 @@ import static com.netflix.spinnaker.orca.ExecutionStatus.SUCCEEDED
class WaitTask implements RetryableTask {
long backoffPeriod = 15000
long timeout = Integer.MAX_VALUE
long waitTimeMs

TimeProvider timeProvider = new TimeProvider()

@Override
long getDynamicBackoffPeriod(Duration taskDuration) {
if (taskDuration <= Duration.ofMillis(waitTimeMs)) {
// wait until timeout is over to poll
return Duration.ofMillis(waitTimeMs).toMillis()
} else {
// start polling normally after timeout to account for delays like throttling
return backoffPeriod
}
}


@Override
TaskResult execute(Stage stage) {
// wait time is specified in seconds
long waitTime = stage.context.waitTime as long
def waitTimeMs = TimeUnit.MILLISECONDS.convert(waitTime, TimeUnit.SECONDS)
waitTimeMs = TimeUnit.MILLISECONDS.convert(waitTime, TimeUnit.SECONDS)
def now = timeProvider.millis

if (!stage.context.containsKey("waitTaskState") || !stage.context.waitTaskState instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.echo.pipeline

import java.time.Duration
import java.util.concurrent.TimeUnit
import com.google.common.annotations.VisibleForTesting
import com.netflix.spinnaker.orca.*
Expand Down Expand Up @@ -65,11 +66,24 @@ class ManualJudgmentStage implements StageDefinitionBuilder, RestartableStage, A
long backoffPeriod = 15000
long timeout = TimeUnit.DAYS.toMillis(3)

@Override
long getDynamicBackoffPeriod(Duration taskDuration) {
if (taskDuration < Duration.ofMillis(timeout)) {
// wait until timeout is over to poll
return Duration.ofMillis(timeout).toMillis()
} else {
// start polling normally after timeout to account for delays like throttling
return backoffPeriod
}
}

@Autowired(required = false)
EchoService echoService

@Override
TaskResult execute(Stage stage) {
stage.getTopLevelTimeout().ifPresent({ timeout = it })

StageData stageData = stage.mapTo(StageData)
NotificationState notificationState
ExecutionStatus executionStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.netflix.spinnaker.orca.controllers

import com.netflix.spinnaker.orca.pipeline.OrchestrationLauncher
import com.netflix.spinnaker.orca.pipeline.model.Task

import java.time.Clock
import com.netflix.spinnaker.orca.ExecutionStatus
import com.netflix.spinnaker.orca.front50.Front50Service
Expand Down Expand Up @@ -262,6 +265,8 @@ class TaskController {
stage.context["lastModifiedBy"] = AuthenticatedRequest.getSpinnakerUser().orElse("anonymous")

executionRepository.storeStage(stage)

executionRunner.reschedule(pipeline)
}
pipeline
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.netflix.spinnaker.orca.controllers

import com.netflix.spinnaker.orca.pipeline.ExecutionRunner

import java.time.Clock
import java.time.Instant
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down Expand Up @@ -45,6 +47,7 @@ class TaskControllerSpec extends Specification {
def executionRepository = Mock(ExecutionRepository)
def front50Service = Mock(Front50Service)
def startTracker = Mock(PipelineStartTracker)
def executionRunner = Mock(ExecutionRunner)

def clock = Clock.fixed(Instant.now(), UTC)
int daysOfExecutionHistory = 14
Expand All @@ -57,6 +60,7 @@ class TaskControllerSpec extends Specification {
new TaskController(
front50Service: front50Service,
executionRepository: executionRepository,
executionRunner: executionRunner,
daysOfExecutionHistory: daysOfExecutionHistory,
numberOfOldPipelineExecutionsToInclude: numberOfOldPipelineExecutionsToInclude,
startTracker: startTracker,
Expand Down Expand Up @@ -293,6 +297,7 @@ class TaskControllerSpec extends Specification {
judgmentStatus: "stop", value: "1", lastModifiedBy: "anonymous"
]
} as Stage)
1 * executionRunner.reschedule(pipeline)
0 * _

and:
Expand Down

0 comments on commit e01058b

Please sign in to comment.