Skip to content

Commit

Permalink
✨ : save job once it is started
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Aug 5, 2019
1 parent 62566fc commit bd6f2c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/codeka/gaia/runner/StackRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/codeka/gaia/runner/StackRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit bd6f2c4

Please sign in to comment.