Skip to content

Commit

Permalink
refactor: replace deprecated functions, remove unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hosekpeter committed Feb 11, 2025
1 parent 97e6093 commit 360ec95
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions pkg/lib/operation/project/remote/job/run/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func Run(ctx context.Context, o RunOptions, d dependencies) (err error) {

queue := &JobQueue{
async: o.Async,
hasQueueV2: d.ProjectFeatures().Has("queuev2"),
ctx: timeoutCtx,
api: d.KeboolaProjectAPI(),
logger: d.Logger(),
Expand Down Expand Up @@ -76,8 +75,7 @@ func Run(ctx context.Context, o RunOptions, d dependencies) (err error) {
}

type JobQueue struct {
async bool
hasQueueV2 bool
async bool

ctx context.Context
api *keboola.AuthorizedAPI
Expand Down Expand Up @@ -145,7 +143,7 @@ func (q *JobQueue) dispatch(job *Job) {
go func() {
defer q.wg.Done()

if err := job.Start(q.ctx, q.api, q.async, q.hasQueueV2); err != nil {
if err := job.Start(q.ctx, q.api); err != nil {
q.err.Append(errors.Errorf("job \"%s\" failed to start: %s", job.Key(), err))
return
}
Expand Down Expand Up @@ -196,47 +194,25 @@ func (o *Job) Key() string {
return out
}

func (o *Job) Start(ctx context.Context, api *keboola.AuthorizedAPI, async bool, hasQueueV2 bool) error {
if hasQueueV2 {
job, err := api.NewCreateJobRequest(o.ComponentID).
WithConfig(o.ConfigID).
WithBranch(o.BranchID).
WithTag(o.Tag).
Send(ctx)
if err != nil {
return err
}
func (o *Job) Start(ctx context.Context, api *keboola.AuthorizedAPI) error {
job, err := api.NewCreateJobRequest(o.ComponentID).
WithConfig(o.ConfigID).
WithBranch(o.BranchID).
WithTag(o.Tag).
Send(ctx)
if err != nil {
return err
}

o.id = job.ID
o.wait = func() error {
err := api.WaitForQueueJob(ctx, job.ID)
if err != nil {
return err
}
return nil
}
} else {
// nolint: staticcheck
job, err := api.CreateOldQueueJobRequest(
o.ComponentID,
o.ConfigID,
keboola.WithBranchID(o.BranchID),
keboola.WithImageTag(o.Tag),
).Send(ctx)
o.id = job.ID
o.wait = func() error {
err := api.WaitForQueueJob(ctx, job.ID)
if err != nil {
return err
}

o.id = job.ID
o.wait = func() error {
// nolint: staticcheck
err := api.WaitForOldQueueJob(ctx, job.ID)
if err != nil {
return err
}
return nil
}
return nil
}

return nil
}

Expand Down

0 comments on commit 360ec95

Please sign in to comment.