From bd6f2c4e2c095e5f8474dfbacd2123c7b6d36e24 Mon Sep 17 00:00:00 2001 From: Cyril Dubuisson Date: Mon, 5 Aug 2019 11:41:11 +0200 Subject: [PATCH] :sparkles: : save job once it is started --- src/main/java/io/codeka/gaia/runner/StackRunner.java | 3 +++ .../java/io/codeka/gaia/runner/StackRunnerTest.java | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/codeka/gaia/runner/StackRunner.java b/src/main/java/io/codeka/gaia/runner/StackRunner.java index 95d9c1857..a8b29997f 100644 --- a/src/main/java/io/codeka/gaia/runner/StackRunner.java +++ b/src/main/java/io/codeka/gaia/runner/StackRunner.java @@ -110,6 +110,7 @@ public void apply(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); job.setCliVersion(module.getCliVersion()); job.start(JobType.RUN); + jobRepository.save(job); var applyScript = stackCommandBuilder.buildApplyScript(stack, module); @@ -143,6 +144,7 @@ public void plan(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); job.setCliVersion(module.getCliVersion()); job.start(JobType.PREVIEW); + jobRepository.save(job); var planScript = stackCommandBuilder.buildPlanScript(stack, module); @@ -191,6 +193,7 @@ public void stop(Job job, TerraformModule module, Stack stack) { this.jobs.put(job.getId(), job); job.setCliVersion(module.getCliVersion()); job.start(JobType.STOP); + jobRepository.save(job); var destroyScript = stackCommandBuilder.buildDestroyScript(stack, module); diff --git a/src/test/java/io/codeka/gaia/runner/StackRunnerTest.java b/src/test/java/io/codeka/gaia/runner/StackRunnerTest.java index 585738fe1..75e3646f9 100644 --- a/src/test/java/io/codeka/gaia/runner/StackRunnerTest.java +++ b/src/test/java/io/codeka/gaia/runner/StackRunnerTest.java @@ -93,7 +93,7 @@ void job_shouldBeSavedToDatabaseAfterRun() throws Exception { stackRunner.apply(job, module, stack); // then - verify(jobRepository).save(job); + verify(jobRepository, times(2)).save(job); } @Test @@ -124,7 +124,7 @@ void plan_shouldUpdateTheStackState_whenThereIsADiffForRunningStacks() throws Ex stackRunner.plan(job, module, stack); // then - verify(jobRepository).save(job); + verify(jobRepository, times(2)).save(job); assertEquals(StackState.TO_UPDATE, stack.getState()); verify(stackRepository).save(stack); @@ -143,7 +143,7 @@ void plan_shouldNotUpdateTheStackState_whenThereIsADiffForNewStacks() throws Exc stackRunner.plan(job, module, stack); // then - verify(jobRepository).save(job); + verify(jobRepository, times(2)).save(job); assertEquals(StackState.NEW, stack.getState()); verifyZeroInteractions(stackRepository); @@ -162,7 +162,7 @@ void stop_shouldUpdateTheStackState_whenSuccessful() throws Exception { stackRunner.stop(job, module, stack); // then - verify(jobRepository).save(job); + verify(jobRepository, times(2)).save(job); assertEquals(StackState.STOPPED, stack.getState()); verify(stackRepository).save(stack); @@ -183,7 +183,7 @@ void jobShouldFail_whenFailingToStartContainer() throws Exception { // then assertEquals(JobStatus.FAILED, job.getStatus()); - verify(jobRepository).save(job); + verify(jobRepository, times(2)).save(job); } @Test