feat(runner): Added waiting for a job arrival in the one-job command.
This commit is contained in:
parent
10a9ab9001
commit
88e6654a6c
1 changed files with 13 additions and 4 deletions
|
|
@ -36,11 +36,20 @@ func NewJob(cfg *config.Config, client client.Client, runner run.RunnerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Job) Run(ctx context.Context) error {
|
func (j *Job) Run(ctx context.Context) error {
|
||||||
|
log.Info("Polling for a job...")
|
||||||
|
for {
|
||||||
task, ok := j.fetchTask(ctx)
|
task, ok := j.fetchTask(ctx)
|
||||||
if !ok {
|
if ok {
|
||||||
return fmt.Errorf("could not fetch task")
|
|
||||||
}
|
|
||||||
return j.runTaskWithRecover(ctx, task)
|
return j.runTaskWithRecover(ctx, task)
|
||||||
|
}
|
||||||
|
// No task available, continue polling
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
default:
|
||||||
|
// Continue to next iteration
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Job) runTaskWithRecover(ctx context.Context, task *runnerv1.Task) error {
|
func (j *Job) runTaskWithRecover(ctx context.Context, task *runnerv1.Task) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue