Skip to content

Commit

Permalink
fix(workflows): start workflow by workflow name
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibbp committed Dec 23, 2023
1 parent b3df484 commit b894e47
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 2 additions & 4 deletions internal/transport/http/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ func (h *Handler) StartWorkflow(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}

workflowId, err := workflows.StartWorkflow(c.Request().Context(), request.WorkflowName)
startWorkflowResponse, err := workflows.StartWorkflow(c.Request().Context(), request.WorkflowName)
if err != nil {
return err
}

return c.JSON(200, map[string]string{
"workflow_id": workflowId,
})
return c.JSON(200, startWorkflowResponse)
}

func (h *Handler) RestartArchiveWorkflow(c echo.Context) error {
Expand Down
30 changes: 17 additions & 13 deletions internal/workflows/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ import (
"go.temporal.io/sdk/client"
)

func StartWorkflow(ctx context.Context, workflowName string) (string, error) {
type StartWorkflowResponse struct {
WorkflowId string `json:"workflow_id"`
RunId string `json:"run_id"`
}

func StartWorkflow(ctx context.Context, workflowName string) (StartWorkflowResponse, error) {
// TODO: develop a better way to do this

wfOptions := client.StartWorkflowOptions{
ID: workflowName,
var startWorkflowResponse StartWorkflowResponse

workflowOptions := client.StartWorkflowOptions{
TaskQueue: "archive",
}

switch workflowName {
case "save_chapters_for_twitch_videos":
we, err := temporal.GetTemporalClient().Client.ExecuteWorkflow(ctx, wfOptions, SaveTwitchVideoChapters)
if err != nil {
log.Error().Err(err).Msg("failed to start workflow")
return "", err
}

return we.GetID(), nil
we, err := temporal.GetTemporalClient().Client.ExecuteWorkflow(ctx, workflowOptions, workflowName)
if err != nil {
log.Error().Err(err).Msg("failed to start workflow")
return startWorkflowResponse, err
}

return "", nil
startWorkflowResponse.WorkflowId = we.GetID()
startWorkflowResponse.RunId = we.GetRunID()

return startWorkflowResponse, nil
}

0 comments on commit b894e47

Please sign in to comment.