Skip to content

Commit

Permalink
fix: check plan.IsTerminated on IsPlanRunning (#432)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: ThibaultFy <thibault.fouqueray@gmail.com>
  • Loading branch information
ThibaultFy authored Jun 13, 2024
1 parent af33711 commit c37696a
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions changes/432.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename `ComputePlanDBAL().IsPlanRunning(key)` to `ComputePlanDBAL().ArePlanTaksRunning(key)`
1 change: 1 addition & 0 deletions changes/432.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`IsPlanRunning` checks if a cancel of failure date is set before checking the tasks status.
10 changes: 7 additions & 3 deletions e2e/computeplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,10 +703,14 @@ func TestIsPlanRunning(t *testing.T) {
require.Nil(t, err)

resp = appClient.IsPlanRunning("cp2")
require.True(t, resp.IsRunning)
require.False(t, resp.IsRunning)

appClient.CancelTask("task-cp2")
appClient.RegisterComputePlan(client.DefaultComputePlanOptions().WithKeyRef("cp3"))
appClient.RegisterTasks(client.DefaultTrainTaskOptions().WithPlanRef("cp3").WithKeyRef("task-cp3"))
appClient.StartTask("task-cp3")

resp = appClient.IsPlanRunning("cp2")
appClient.CancelTask("task-cp3")

resp = appClient.IsPlanRunning("cp3")
require.False(t, resp.IsRunning)
}
2 changes: 1 addition & 1 deletion lib/persistence/computeplan_dbal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ComputePlanDBAL interface {
SetComputePlanName(plan *asset.ComputePlan, name string) error
CancelComputePlan(plan *asset.ComputePlan, cancelationDate time.Time) error
FailComputePlan(plan *asset.ComputePlan, failureDate time.Time) error
IsPlanRunning(key string) (bool, error)
ArePlanTasksRunning(key string) (bool, error)
}

type ComputePlanDBALProvider interface {
Expand Down
7 changes: 6 additions & 1 deletion lib/service/computeplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,10 @@ func (s *ComputePlanService) computePlanExists(key string) (bool, error) {
// IsPlanRunning indicates whether there are tasks belonging to the compute plan
// being executed or waiting to be executed
func (s *ComputePlanService) IsPlanRunning(key string) (bool, error) {
return s.GetComputePlanDBAL().IsPlanRunning(key)
plan, err := s.GetPlan(key)
if plan.IsTerminated() {
return false, err
} else {
return s.GetComputePlanDBAL().ArePlanTasksRunning(key)
}
}
14 changes: 1 addition & 13 deletions lib/service/computetaskstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,7 @@ func (s *ComputeTaskService) applyTaskAction(task *asset.ComputeTask, action ass
case asset.ComputeTaskAction_TASK_ACTION_FAILED:
transition = transitionFailed
case asset.ComputeTaskAction_TASK_ACTION_DONE:
if task.ComputePlanKey != "" {
plan, err := s.GetComputePlanService().GetPlan(task.ComputePlanKey)
if err != nil {
return err
}
if plan.IsTerminated() {
transition = transitionCanceled
} else {
transition = transitionDone
}
} else {
transition = transitionDone
}
transition = transitionDone
case asset.ComputeTaskAction_TASK_ACTION_BUILD_STARTED:
transition = transitionBuilding
case asset.ComputeTaskAction_TASK_ACTION_BUILD_FINISHED:
Expand Down
2 changes: 1 addition & 1 deletion server/standalone/dbal/computeplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (d *DBAL) FailComputePlan(plan *asset.ComputePlan, failureDate time.Time) e
return d.updateComputePlan(plan.Key, "failure_date", failureDate)
}

func (d *DBAL) IsPlanRunning(key string) (bool, error) {
func (d *DBAL) ArePlanTasksRunning(key string) (bool, error) {
stmt := getStatementBuilder().
Select("status",
"COUNT(status)").
Expand Down
2 changes: 1 addition & 1 deletion server/standalone/dbal/computeplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestIsPlanRunning(t *testing.T) {

dbal := &DBAL{ctx: context.TODO(), tx: tx, channel: testChannel}

isRunning, err := dbal.IsPlanRunning(cpKey)
isRunning, err := dbal.ArePlanTasksRunning(cpKey)
assert.NoError(t, err)
assert.True(t, isRunning)

Expand Down

0 comments on commit c37696a

Please sign in to comment.