drone/internal/pipeline/runner/poller.go
2023-09-15 15:56:35 +00:00

46 lines
1.2 KiB
Go

// Copyright 2022 Harness Inc. All rights reserved.
// Use of this source code is governed by the Polyform Free Trial License
// that can be found in the LICENSE.md file for this repository.
package runner
import (
"context"
"fmt"
"runtime/debug"
"github.com/harness/gitness/types"
"github.com/drone-runners/drone-runner-docker/engine/resource"
runtime2 "github.com/drone-runners/drone-runner-docker/engine2/runtime"
"github.com/drone/drone-go/drone"
runnerclient "github.com/drone/runner-go/client"
"github.com/drone/runner-go/poller"
)
func NewExecutionPoller(
runner *runtime2.Runner,
config *types.Config,
client runnerclient.Client,
) *poller.Poller {
// taking the cautious approach of recovering in case of panics
runWithRecovery := func(ctx context.Context, stage *drone.Stage) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic received while executing run: %s", debug.Stack())
}
}()
return runner.Run(ctx, stage)
}
return &poller.Poller{
Client: client,
Dispatch: runWithRecovery,
Filter: &runnerclient.Filter{
Kind: resource.Kind,
Type: resource.Type,
// TODO: Check if other parameters are needed.
},
}
}