Skip to content

Commit

Permalink
fix(queue): After trying to start a queued execution that is CANCELED…
Browse files Browse the repository at this point in the history
…, check the pipeline queue for additional waiting executions (#3015)
  • Loading branch information
christopherthielen committed Jun 26, 2019
1 parent 0b42263 commit 2a8492b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.q.CancelExecution
import com.netflix.spinnaker.orca.q.StartExecution
import com.netflix.spinnaker.orca.q.StartStage
import com.netflix.spinnaker.orca.q.StartWaitingExecutions
import com.netflix.spinnaker.orca.q.pending.PendingExecutionService
import com.netflix.spinnaker.q.Queue
import net.logstash.logback.argument.StructuredArguments.value
Expand Down Expand Up @@ -99,6 +100,9 @@ class StartExecutionHandler(
private fun terminate(execution: Execution) {
if (execution.status == CANCELED || execution.isCanceled) {
publisher.publishEvent(ExecutionComplete(this, execution.type, execution.id, execution.status))
execution.pipelineConfigId?.let {
queue.push(StartWaitingExecutions(it, purgeQueue = !execution.isKeepWaitingPipelines))
}
} else {
log.warn("Execution (type: ${execution.type}, id: {}, status: ${execution.status}, application: {})" +
" cannot be started unless state is NOT_STARTED. Ignoring StartExecution message.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.q.CancelExecution
import com.netflix.spinnaker.orca.q.StartExecution
import com.netflix.spinnaker.orca.q.StartStage
import com.netflix.spinnaker.orca.q.StartWaitingExecutions
import com.netflix.spinnaker.orca.q.pending.PendingExecutionService
import com.netflix.spinnaker.orca.q.singleTaskStage
import com.netflix.spinnaker.q.Queue
Expand Down Expand Up @@ -140,7 +141,7 @@ object StartExecutionHandlerTest : SubjectSpek<StartExecutionHandler>({
}
}

given("a pipeline that was previously canceled and status is NOT_STARTED") {
given("a pipeline with no pipelineConfigId that was previously canceled and status is NOT_STARTED") {
val pipeline = pipeline {
stage {
type = singleTaskStage.type
Expand Down Expand Up @@ -173,6 +174,33 @@ object StartExecutionHandlerTest : SubjectSpek<StartExecutionHandler>({
}
}

given("a pipeline with a pipelineConfigId that was previously canceled and status is NOT_STARTED") {
val pipeline = pipeline {
pipelineConfigId = "aaaaa-12345-bbbbb-67890"
isKeepWaitingPipelines = false
stage {
type = singleTaskStage.type
}
isCanceled = true
}

val message = StartExecution(pipeline)

beforeGroup {
whenever(repository.retrieve(message.executionType, message.executionId)) doReturn pipeline
}

afterGroup(::resetMocks)

on("receiving a message") {
subject.handle(message)
}

it("starts waiting executions for the pipelineConfigId") {
verify(queue).push(StartWaitingExecutions("aaaaa-12345-bbbbb-67890", true))
}
}

given("a pipeline with multiple initial stages") {
val pipeline = pipeline {
stage {
Expand Down

0 comments on commit 2a8492b

Please sign in to comment.