-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: bad project path * fix: remove tickerId for replay * feat: cancel from request * feat: cancel button in UI * chore: rm comment * fix: build error * chore: reason case * chore: reason string * fix: linting --------- Co-authored-by: gabriel ruttner <gabe@hatchet.run>
- Loading branch information
Showing
14 changed files
with
2,757 additions
and
1,861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package stepruns | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/labstack/echo/v4" | ||
|
||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors" | ||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen" | ||
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers" | ||
"github.com/hatchet-dev/hatchet/internal/msgqueue" | ||
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db" | ||
"github.com/hatchet-dev/hatchet/internal/services/shared/tasktypes" | ||
) | ||
|
||
func (t *StepRunService) StepRunUpdateCancel(ctx echo.Context, request gen.StepRunUpdateCancelRequestObject) (gen.StepRunUpdateCancelResponseObject, error) { | ||
tenant := ctx.Get("tenant").(*db.TenantModel) | ||
stepRun := ctx.Get("step-run").(*db.StepRunModel) | ||
|
||
// check to see if the step run is in a running or pending state | ||
status := stepRun.Status | ||
|
||
if status == db.StepRunStatusFailed || status == db.StepRunStatusCancelled || status == db.StepRunStatusSucceeded { | ||
return gen.StepRunUpdateCancel400JSONResponse( | ||
apierrors.NewAPIErrors("step run is not in a running or pending state"), | ||
), nil | ||
} | ||
|
||
engineStepRun, err := t.config.EngineRepository.StepRun().GetStepRunForEngine(tenant.ID, stepRun.ID) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not get step run for engine: %w", err) | ||
} | ||
|
||
var reason = "CANCELLED_BY_USER" | ||
|
||
// send a task to the taskqueue | ||
err = t.config.MessageQueue.AddMessage( | ||
ctx.Request().Context(), | ||
msgqueue.JOB_PROCESSING_QUEUE, | ||
tasktypes.StepRunCancelToTask(engineStepRun, reason), | ||
) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not add step queued task to task queue: %w", err) | ||
} | ||
|
||
// wait for a short period of time | ||
for i := 0; i < 5; i++ { | ||
newStepRun, err := t.config.APIRepository.StepRun().GetStepRunById(tenant.ID, stepRun.ID) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not get step run: %w", err) | ||
} | ||
|
||
if newStepRun.Status != stepRun.Status { | ||
stepRun = newStepRun | ||
break | ||
} | ||
|
||
time.Sleep(100 * time.Millisecond) | ||
} | ||
|
||
res, err := transformers.ToStepRun(stepRun) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("could not transform step run: %w", err) | ||
} | ||
|
||
return gen.StepRunUpdateCancel200JSONResponse( | ||
*res, | ||
), nil | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.