Skip to content

Commit

Permalink
Merge pull request #138 from atomist-skills/tweaks-to-allow-for-async…
Browse files Browse the repository at this point in the history
…-executions

a couple of tweaks to allow for async skill execution
  • Loading branch information
chrispatrick authored Oct 14, 2024
2 parents 7bf75f3 + 801cda5 commit d320712
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 4 additions & 4 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func CreateHttpHandlerWithLogger(handlers Handlers, loggerCreator CreateLogger)

defer func() {
if err := recover(); err != nil {
sendStatus(ctx, req, Status{
SendStatus(ctx, req, Status{
State: Failed,
Reason: fmt.Sprintf("Unsuccessfully invoked handler %s/%s@%s", event.Skill.Namespace, event.Skill.Name, name),
})
Expand All @@ -106,7 +106,7 @@ func CreateHttpHandlerWithLogger(handlers Handlers, loggerCreator CreateLogger)
if handle, ok := handlers[name]; ok {
logger.Debugf("Invoking event handler '%s'", name)

err = sendStatus(ctx, req, Status{
err = SendStatus(ctx, req, Status{
State: running,
})
if err != nil {
Expand All @@ -115,7 +115,7 @@ func CreateHttpHandlerWithLogger(handlers Handlers, loggerCreator CreateLogger)

status := handle(ctx, req)

err = sendStatus(ctx, req, status)
err = SendStatus(ctx, req, status)
if err != nil {
Log.Panicf("Failed to send status: %s", err)
}
Expand All @@ -134,7 +134,7 @@ func CreateHttpHandlerWithLogger(handlers Handlers, loggerCreator CreateLogger)
w.Write(b)
}
} else {
err = sendStatus(ctx, req, Status{
err = SendStatus(ctx, req, Status{
State: Failed,
Reason: fmt.Sprintf("Event handler '%s' not found", name),
})
Expand Down
9 changes: 8 additions & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ func NewRetryableStatus(reason string) Status {
}
}

func sendStatus(ctx context.Context, req RequestContext, status Status) error {
func NewRunningStatus(reason string) Status {
return Status{
State: running,
Reason: reason,
}
}

func SendStatus(ctx context.Context, req RequestContext, status Status) error {
// Don't send the status when evaluating policies locally
if os.Getenv("SCOUT_LOCAL_POLICY_EVALUATION") == "true" {
return nil
Expand Down

0 comments on commit d320712

Please sign in to comment.