Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support new JOBS api #128

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Run linter
uses: golangci/[email protected] # Action page: <https://github.com/golangci/golangci-lint-action>
with:
version: v1.56 # without patch version
version: v1.59 # without patch version
only-new-issues: false # show only new issues if it's a pull request
args: --timeout=10m --build-tags=race ./...
16 changes: 3 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# Documentation: <https://github.com/golangci/golangci-lint#config-file>

run:
timeout: 1m
skip-dirs:
- .github
- .git
allow-parallel-runners: true

output:
format: colored-line-number # colored-line-number|line-number|json|tab|checkstyle|code-climate

linters-settings:
wsl:
allow-assign-and-anything: true
govet:
check-shadowing: true
golint:
min-confidence: 0.1
godot:
scope: declarations
capital: true
Expand All @@ -34,7 +22,6 @@ linters-settings:
range-loops: true
for-loops: true
nolintlint:
allow-leading-space: false
require-specific: true

linters: # All available linters list: <https://golangci-lint.run/usage/linters/>
Expand Down Expand Up @@ -75,6 +62,9 @@ linters: # All available linters list: <https://golangci-lint.run/usage/linters/
- whitespace # Tool for detection of leading and trailing whitespace

issues:
exclude-dirs:
- .github
- .git
exclude-rules:
- path: _test\.go
linters:
Expand Down
2 changes: 1 addition & 1 deletion boltjobs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sync/atomic"
"time"

"github.com/roadrunner-server/api/v4/plugins/v3/jobs"
"github.com/roadrunner-server/api/v4/plugins/v4/jobs"
"github.com/roadrunner-server/errors"
bolt "go.etcd.io/bbolt"
jprop "go.opentelemetry.io/contrib/propagators/jaeger"
Expand Down
31 changes: 25 additions & 6 deletions boltjobs/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
import (
"bytes"
"encoding/gob"
"maps"
"sync/atomic"
"time"
"unsafe"

"github.com/goccy/go-json"
"github.com/roadrunner-server/api/v4/plugins/v3/jobs"
"github.com/roadrunner-server/api/v4/plugins/v4/jobs"
"github.com/roadrunner-server/errors"
"go.etcd.io/bbolt"
)

var _ jobs.Job = (*Item)(nil)

type Item struct {
// Job contains pluginName of job broker (usually PHP class).
Job string `json:"job"`
Expand All @@ -34,7 +37,7 @@
// Pipeline manually specified pipeline.
Pipeline string `json:"pipeline,omitempty"`
// Delay defines time duration to delay execution for. Defaults to none.
Delay int64 `json:"delay,omitempty"`
Delay int `json:"delay,omitempty"`
rustatian marked this conversation as resolved.
Show resolved Hide resolved
// AutoAck option
AutoAck bool `json:"auto_ack"`
// Push bucket
Expand Down Expand Up @@ -125,13 +128,26 @@
return tx.Commit()
}

func (i *Item) NackWithOptions(requeue bool, delay int) error {
// don't NACK the job when it was already ack'ed
if i.Options.AutoAck {
return nil
}

if requeue {
return i.Requeue(nil, delay)
}

return i.Nack()
}

func (i *Item) Nack() error {
// don't NACK the job when it was already ack'ed
if i.Options.AutoAck {
return nil
}

const op = errors.Op("boltdb_item_ack")
const op = errors.Op("boltdb_item_nack")
/*
steps:
1. begin tx
Expand Down Expand Up @@ -179,9 +195,12 @@
4.3. Put this key with value to the DelayBucket
5. W/o delay, put the key with value to the PushBucket (requeue)
*/
func (i *Item) Requeue(headers map[string][]string, delay int64) error {
func (i *Item) Requeue(headers map[string][]string, delay int) error {
const op = errors.Op("boltdb_item_requeue")
i.headers = headers
if headers != nil && len(headers) > 0 {

Check failure on line 200 in boltjobs/item.go

View workflow job for this annotation

GitHub Actions / Golang-CI (lint)

S1009: should omit nil check; len() for map[string][]string is defined as zero (gosimple)

Check failure on line 200 in boltjobs/item.go

View workflow job for this annotation

GitHub Actions / Golang-CI (lint)

S1009: should omit nil check; len() for map[string][]string is defined as zero (gosimple)
maps.Copy(i.headers, headers)
}

rustatian marked this conversation as resolved.
Show resolved Hide resolved
i.Options.Delay = delay

tx, err := i.Options.db.Begin(true)
Expand Down Expand Up @@ -260,7 +279,7 @@
AutoAck: job.AutoAck(),
Priority: job.Priority(),
Pipeline: job.GroupID(),
Delay: job.Delay(),
Delay: int(job.Delay()),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.4

require (
github.com/goccy/go-json v0.10.3
github.com/roadrunner-server/api/v4 v4.12.0
github.com/roadrunner-server/api/v4 v4.13.0
github.com/roadrunner-server/endure/v2 v2.4.5
github.com/roadrunner-server/errors v1.4.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/roadrunner-server/api/v4 v4.12.0 h1:N8AC+b7uzrDpTPnFTBVWNIs9ZMV42hwKDCo29X84iS8=
github.com/roadrunner-server/api/v4 v4.12.0/go.mod h1:nLV2f4O7tDh5DaMDff4oX1bNJ9erz7eyq+4TajgKGck=
github.com/roadrunner-server/api/v4 v4.13.0 h1:ciC5nzkIHqfbnzFgaUb1If/+fKLbL39OVqUdnEKrXdE=
github.com/roadrunner-server/api/v4 v4.13.0/go.mod h1:J8ZzDCNFs3BQDql793eBeshpjNJxLrCpEMooGzapTLo=
github.com/roadrunner-server/endure/v2 v2.4.5 h1:GoZm/1HjKCKm8TpaP/Pm2KbN0X9gLyN840cA3Fn/TCE=
github.com/roadrunner-server/endure/v2 v2.4.5/go.mod h1:83UvLdt+RNxELTSna+SZMWQiu+Thj6wOz6hmlp65XFI=
github.com/roadrunner-server/errors v1.4.0 h1:Odjg3VZrj1q5Y8ILwoN+JgERyv0pkhrWPNOM4h68iQ8=
Expand Down
Loading
Loading