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 plugins api #122

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e -o pipefail

# https://github.com/koalaman/shellcheck/wiki/SC2039#redirect-both-stdout-and-stderr
if ! command -v golangci-lint 2>&1 /dev/null; then
echo "golangci-lint is not installed"
exit 1
fi

exec golangci-lint --build-tags=race run "$@"
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.54 # 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 ./...
6 changes: 3 additions & 3 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
php: [ "8.2" ]
go: [ stable ]
os: [ "ubuntu-latest" ]
php: ["8.3"]
go: [stable]
os: ["ubuntu-latest"]
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5 # action page: <https://github.com/actions/setup-go>
Expand Down
14 changes: 3 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@

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
gocyclo:
min-complexity: 15
godot:
Expand All @@ -36,7 +26,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 @@ -78,6 +67,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 beanstalkjobs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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"
jprop "go.opentelemetry.io/contrib/propagators/jaeger"
"go.opentelemetry.io/otel"
Expand Down
32 changes: 27 additions & 5 deletions beanstalkjobs/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import (
"bytes"
"context"
"encoding/gob"
"maps"
"sync/atomic"
"time"

"github.com/beanstalkd/go-beanstalk"
"github.com/goccy/go-json"
"github.com/google/uuid"
"github.com/roadrunner-server/api/v4/plugins/v3/jobs"
"github.com/roadrunner-server/api/v4/plugins/v4/jobs"
"go.uber.org/zap"
)

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

const (
auto string = "deduced_by_rr"
)
Expand All @@ -39,7 +42,7 @@ type Options struct {
// 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"`
// Beanstalk Tube
Expand Down Expand Up @@ -112,17 +115,36 @@ func (i *Item) Ack() error {
return i.Options.conn.Load().Delete(i.Options.id)
}

func (i *Item) NackWithOptions(redeliver bool, delay int) error {
if i.Options.AutoAck {
return nil
}

if redeliver {
i.Options.Delay = delay
err := i.Options.requeueFn(context.Background(), i)
if err != nil {
return err
}

return nil
}

return i.Options.conn.Load().Delete(i.Options.id)
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved

func (i *Item) Nack() error {
if i.Options.AutoAck {
return nil
}

return i.Options.conn.Load().Delete(i.Options.id)
}

func (i *Item) Requeue(headers map[string][]string, delay int64) error {
func (i *Item) Requeue(headers map[string][]string, delay int) error {
// overwrite the delay
i.Options.Delay = delay
i.headers = headers
maps.Copy(i.headers, headers)
rustatian marked this conversation as resolved.
Show resolved Hide resolved

err := i.Options.requeueFn(context.Background(), i)
if err != nil {
Expand Down Expand Up @@ -152,7 +174,7 @@ func fromJob(job jobs.Message) *Item {
AutoAck: job.AutoAck(),
Priority: job.Priority(),
Pipeline: job.GroupID(),
Delay: job.Delay(),
Delay: int(job.Delay()),
},
}
}
Expand Down
7 changes: 7 additions & 0 deletions githooks-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

set -e

cp ./.githooks/pre-commit .git/hooks/pre-commit

echo "DONE"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/goccy/go-json v0.10.3
github.com/google/uuid v1.6.0
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
go.opentelemetry.io/contrib/propagators/jaeger v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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