Skip to content

Commit 7ea6a99

Browse files
committed
fixes
1 parent 7a229d9 commit 7ea6a99

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

server/internal/background/deployments.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,28 +184,6 @@ func ProcessDeploymentWorkflow(ctx workflow.Context, params ProcessDeploymentWor
184184
)
185185
}
186186

187-
// Trigger project-scoped functions reaper workflow after successful deployment
188-
// This runs asynchronously and doesn't block the deployment workflow
189-
if finalStatus == "completed" {
190-
logger.Info(
191-
"starting project-scoped function reaper",
192-
string(attr.ProjectIDKey), params.ProjectID,
193-
string(attr.DeploymentIDKey), params.DeploymentID,
194-
)
195-
_, err = ExecuteProjectFunctionsReaperChildWorkflow(ctx, params.ProjectID)
196-
// Many deployments can run in parallel in a given project but only one
197-
// reaper should be active at a time, so we ignore the already started
198-
// error if we get that back.
199-
if err != nil && !temporal.IsWorkflowExecutionAlreadyStartedError(err) {
200-
logger.Error(
201-
"failed to start project-scoped functions reaper workflow",
202-
"error", err.Error(),
203-
string(attr.ProjectIDKey), params.ProjectID,
204-
string(attr.DeploymentIDKey), params.DeploymentID,
205-
)
206-
}
207-
}
208-
209187
return &ProcessDeploymentWorkflowResult{
210188
ProjectID: params.ProjectID,
211189
DeploymentID: params.DeploymentID,

server/internal/background/functions_reaper.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package background
22

33
import (
4+
"context"
45
"fmt"
56
"time"
67

78
"go.temporal.io/api/enums/v1"
9+
"go.temporal.io/sdk/client"
810
"go.temporal.io/sdk/temporal"
911
"go.temporal.io/sdk/workflow"
1012

@@ -23,18 +25,17 @@ type FunctionsReaperWorkflowResult struct {
2325
Errors int
2426
}
2527

26-
func ExecuteProjectFunctionsReaperChildWorkflow(ctx workflow.Context, projectID uuid.UUID) (workflow.ChildWorkflowFuture, error) {
27-
ctx = workflow.WithChildOptions(ctx, workflow.ChildWorkflowOptions{
28-
WorkflowID: "v1:functions-reaper:" + projectID.String(),
29-
TaskQueue: string(TaskQueueMain),
30-
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY,
31-
WorkflowRunTimeout: time.Minute * 10,
32-
})
33-
34-
return workflow.ExecuteChildWorkflow(ctx, FunctionsReaperWorkflow, FunctionsReaperWorkflowParams{
28+
func ExecuteProjectFunctionsReaperWorkflow(ctx context.Context, temporalClient client.Client, projectID uuid.UUID) (client.WorkflowRun, error) {
29+
return temporalClient.ExecuteWorkflow(ctx, client.StartWorkflowOptions{
30+
ID: "v1:functions-reaper:" + projectID.String(),
31+
TaskQueue: string(TaskQueueMain),
32+
WorkflowIDConflictPolicy: enums.WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING,
33+
WorkflowIDReusePolicy: enums.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE,
34+
WorkflowRunTimeout: time.Minute * 2,
35+
}, ProcessDeploymentWorkflow, FunctionsReaperWorkflowParams{
3536
Scope: activities.FunctionsReaperScopeProject,
3637
ProjectID: uuid.NullUUID{UUID: projectID, Valid: projectID != uuid.Nil},
37-
}), nil
38+
})
3839
}
3940

4041
func FunctionsReaperWorkflow(ctx workflow.Context, params FunctionsReaperWorkflowParams) (*FunctionsReaperWorkflowResult, error) {

server/internal/deployments/impl.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/speakeasy-api/gram/server/internal/packages/semver"
3737
"github.com/speakeasy-api/gram/server/internal/thirdparty/posthog"
3838
"go.temporal.io/sdk/client"
39+
"go.temporal.io/sdk/temporal"
3940
)
4041

4142
type Service struct {
@@ -846,6 +847,17 @@ func (s *Service) resolvePackages(ctx context.Context, tx *packagesRepo.Queries,
846847
}
847848

848849
func (s *Service) startDeployment(ctx context.Context, logger *slog.Logger, projectID uuid.UUID, deploymentID uuid.UUID, dep *types.Deployment) (string, error) {
850+
defer func() {
851+
logger.InfoContext(ctx, "starting project-scoped functions reaper")
852+
_, err := background.ExecuteProjectFunctionsReaperWorkflow(ctx, s.temporal, projectID)
853+
if err != nil && !temporal.IsWorkflowExecutionAlreadyStartedError(err) {
854+
logger.ErrorContext(
855+
ctx, "failed to start project-scoped functions reaper workflow",
856+
attr.SlogError(err),
857+
)
858+
}
859+
}()
860+
849861
wr, err := background.ExecuteProcessDeploymentWorkflow(ctx, s.temporal, background.ProcessDeploymentWorkflowParams{
850862
ProjectID: projectID,
851863
DeploymentID: deploymentID,

server/internal/functions/deploy_fly.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,18 @@ func (f *FlyRunner) reap(ctx context.Context, logger *slog.Logger, appsRepo *rep
582582
}
583583

584584
reapErrorMessage := ""
585-
if err := f.client.DeleteApp(ctx, app.AppName); err != nil {
586-
// Log error but continue - we still want to mark it as reaped in the database
587-
reapErrorMessage = err.Error()
588-
logger.WarnContext(ctx, "delete app request failed", attr.SlogError(err))
585+
if res.StatusCode >= 400 {
586+
bodyBytes, readErr := io.ReadAll(res.Body)
587+
if readErr == nil {
588+
message := string(bodyBytes)
589+
if len(message) > 500 {
590+
message = message[:500]
591+
}
592+
593+
reapErrorMessage = fmt.Sprintf("status %d: %s", res.StatusCode, message)
594+
} else {
595+
reapErrorMessage = fmt.Sprintf("status %d: failed to read response body: %v", res.StatusCode, readErr)
596+
}
589597
}
590598

591599
// Mark the app as reaped in the database

0 commit comments

Comments
 (0)