Skip to content

Commit f8605e5

Browse files
authored
[#7]: feat(API): API unification, move all SDK interfaces to the API
2 parents cd52d66 + b1b14bd commit f8605e5

File tree

27 files changed

+737
-251
lines changed

27 files changed

+737
-251
lines changed

.github/workflows/linux.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Linux
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- beta
8+
- stable
9+
tags-ignore:
10+
- "**"
11+
paths-ignore:
12+
- "**.md"
13+
- "**.yaml"
14+
- "**.yml"
15+
pull_request:
16+
paths-ignore:
17+
- "**.md"
18+
- "**.yaml"
19+
- "**.yml"
20+
21+
jobs:
22+
golang:
23+
name: Build (Go ${{ matrix.go }}, OS ${{matrix.os}})
24+
runs-on: ${{ matrix.os }}
25+
timeout-minutes: 60
26+
strategy:
27+
fail-fast: true
28+
matrix:
29+
go: ["1.17.7"]
30+
os: ["ubuntu-latest"]
31+
steps:
32+
- name: Set up Go ${{ matrix.go }}
33+
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go>
34+
with:
35+
go-version: ${{ matrix.go }}
36+
37+
- name: Check out code
38+
uses: actions/checkout@v2
39+
40+
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules>
41+
uses: actions/cache@v2
42+
with:
43+
path: ~/go/pkg/mod
44+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
45+
restore-keys: ${{ runner.os }}-go-
46+
47+
- name: Install Go dependencies
48+
run: go mod download
49+
50+
- name: Run golang tests with coverage
51+
run: make test

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ SHELL = /bin/sh
77
test_coverage:
88
rm -rf coverage-ci
99
mkdir ./coverage-ci
10-
go test -v -race -cover -tags=debug -coverpkg=./... -failfast -coverprofile=./coverage-ci/pipeline_jobs.out -covermode=atomic ./plugins/v2/jobs/pipeline
10+
go test -v -race -cover -tags=debug -coverpkg=./... -failfast -coverprofile=./coverage-ci/pipeline_jobs.out -covermode=atomic ./plugins/jobs/pipeline
1111
echo 'mode: atomic' > ./coverage-ci/summary.txt
1212
tail -q -n +2 ./coverage-ci/*.out >> ./coverage-ci/summary.txt
1313

1414
test: ## Run application tests
15-
go test -v -race -tags=debug ./plugins/v2/jobs/pipeline
15+
go test -v -race -tags=debug ./plugins/jobs/pipeline
1616

1717
generate-proto:
1818
protoc -I./proto/jobs/v1beta --go_out=./proto/jobs/v1beta jobs.proto

bst/bst.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package bst
2+
3+
// Storage is general in-memory BST storage implementation
4+
type Storage interface {
5+
// Insert inserts to a vertex with topic ident connection uuid
6+
Insert(uuid string, topic string)
7+
// Remove removes uuid from topic, if the uuid is single for a topic, whole vertex will be removed
8+
Remove(uuid, topic string)
9+
// Get will return all connections associated with the topic
10+
Get(topic string) map[string]struct{}
11+
// Contains checks if the BST contains a topic
12+
Contains(topic string) bool
13+
}

event_bus/events.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package event_bus //nolint:stylecheck
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type EventBus interface {
8+
SubscribeAll(subID string, ch chan<- Event) error
9+
SubscribeP(subID string, pattern string, ch chan<- Event) error
10+
Unsubscribe(subID string)
11+
UnsubscribeP(subID, pattern string)
12+
Len() uint
13+
Send(ev Event)
14+
}
15+
16+
type Event interface {
17+
Type() fmt.Stringer
18+
Plugin() string
19+
Message() string
20+
}

go.mod

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.17
55
require (
66
github.com/goccy/go-json v0.9.4
77
github.com/prometheus/client_golang v1.12.1
8-
github.com/roadrunner-server/sdk/v2 v2.8.1
8+
github.com/roadrunner-server/goridge/v3 v3.3.1
99
github.com/stretchr/testify v1.7.0
1010
github.com/valyala/fasthttp v1.33.0
1111
go.uber.org/zap v1.21.0
@@ -17,28 +17,18 @@ require (
1717
github.com/beorn7/perks v1.0.1 // indirect
1818
github.com/cespare/xxhash/v2 v2.1.2 // indirect
1919
github.com/davecgh/go-spew v1.1.1 // indirect
20-
github.com/go-ole/go-ole v1.2.6 // indirect
2120
github.com/golang/protobuf v1.5.2 // indirect
2221
github.com/google/go-cmp v0.5.6 // indirect
23-
github.com/google/uuid v1.3.0 // indirect
2422
github.com/klauspost/compress v1.14.2 // indirect
2523
github.com/kr/pretty v0.2.0 // indirect
2624
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
2725
github.com/pmezard/go-difflib v1.0.0 // indirect
2826
github.com/prometheus/client_model v0.2.0 // indirect
2927
github.com/prometheus/common v0.32.1 // indirect
3028
github.com/prometheus/procfs v0.7.3 // indirect
31-
github.com/roadrunner-server/errors v1.1.1 // indirect
32-
github.com/roadrunner-server/goridge/v3 v3.3.1 // indirect
33-
github.com/roadrunner-server/tcplisten v1.1.1 // indirect
34-
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
35-
github.com/tklauser/go-sysconf v0.3.9 // indirect
36-
github.com/tklauser/numcpus v0.4.0 // indirect
3729
github.com/valyala/bytebufferpool v1.0.0 // indirect
38-
github.com/yusufpapurcu/wmi v1.2.2 // indirect
3930
go.uber.org/atomic v1.9.0 // indirect
4031
go.uber.org/multierr v1.7.0 // indirect
41-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
4232
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
4333
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
4434
)

go.sum

+1-23
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
7171
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
7272
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
7373
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
74-
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
75-
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
7674
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
7775
github.com/goccy/go-json v0.9.4 h1:L8MLKG2mvVXiQu07qB6hmfqeSYQdOnqPot2GhsIwIaI=
7876
github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
@@ -129,8 +127,6 @@ github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hf
129127
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
130128
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
131129
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
132-
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
133-
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
134130
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
135131
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
136132
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
@@ -195,33 +191,22 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
195191
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
196192
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
197193
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
198-
github.com/roadrunner-server/errors v1.1.1 h1:BzrB+xZE+iTISVfXSzIL9YbpPt6oHoRHgOBjlU/pigQ=
199194
github.com/roadrunner-server/errors v1.1.1/go.mod h1:MzHjhRZIZc1ooMyYllUhNs0aTqRUbwcgUSO0TN7kCII=
200195
github.com/roadrunner-server/goridge/v3 v3.3.1 h1:IYdm+smDfKl09AfFgKJeSNpSTp7KTgO3XfGPKrxs0vQ=
201196
github.com/roadrunner-server/goridge/v3 v3.3.1/go.mod h1:f7SPSt9HUw5kbCc6Ofk4eEUU1xh2qHf/NznrTaW+aLA=
202-
github.com/roadrunner-server/sdk/v2 v2.8.1 h1:QneTXD31gBmiEV5q+Cd4yDgoPCkKJZj+zrV1PLXp6dM=
203-
github.com/roadrunner-server/sdk/v2 v2.8.1/go.mod h1:oqohHdPseV3P3woXk3H1XUnU8YeprC63O8wRmjCkP5Q=
204-
github.com/roadrunner-server/tcplisten v1.1.1 h1:uVJVdg/zaasD2A4Mg+GyMlsUy2nLp9ADKec/REzql9Y=
205-
github.com/roadrunner-server/tcplisten v1.1.1/go.mod h1:2MjzsggdgxCca4p2k3YJdWdo/QnQehiOTy0knlE226c=
206197
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
207-
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
208-
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
209198
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
210199
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
211200
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
212201
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
202+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
213203
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
214204
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
215205
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
216206
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
217207
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
218208
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
219209
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
220-
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
221-
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
222-
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
223-
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
224-
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
225210
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
226211
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
227212
github.com/valyala/fasthttp v1.33.0 h1:mHBKd98J5NcXuBddgjvim1i3kWzlng1SzLhrnBOU9g8=
@@ -233,8 +218,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
233218
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
234219
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
235220
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
236-
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
237-
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
238221
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
239222
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
240223
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
@@ -335,7 +318,6 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ
335318
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
336319
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
337320
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
338-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
339321
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
340322
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
341323
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -349,7 +331,6 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
349331
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
350332
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
351333
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
352-
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
353334
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
354335
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
355336
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -376,11 +357,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
376357
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
377358
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
378359
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
379-
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
380360
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
381361
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
382-
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
383-
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
384362
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
385363
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
386364
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

internal/race_checker.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//go:build race
2+
3+
package internal
4+
5+
import (
6+
"crypto/sha512"
7+
"fmt"
8+
"runtime"
9+
)
10+
11+
func SetChecker(b []byte) {
12+
if len(b) == 0 {
13+
return
14+
}
15+
c := checkIfConst(b)
16+
go c.isStillConst()
17+
runtime.SetFinalizer(c, (*constSlice).isStillConst)
18+
}
19+
20+
type constSlice struct {
21+
b []byte
22+
checksum [64]byte
23+
}
24+
25+
func checkIfConst(b []byte) *constSlice {
26+
c := &constSlice{b: b}
27+
c.checksum = sha512.Sum512(c.b)
28+
return c
29+
}
30+
31+
func (c *constSlice) isStillConst() {
32+
if sha512.Sum512(c.b) != c.checksum {
33+
panic(fmt.Sprintf("mutable access detected 0x%012x", &c.b[0]))
34+
}
35+
}

internal/race_checker_unsafe.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build !race
2+
3+
package internal
4+
5+
func SetChecker(_ []byte) {}

internal/utils.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package internal
2+
3+
import (
4+
"reflect"
5+
"unsafe"
6+
)
7+
8+
// AsBytes returns a slice that refers to the data backing the string s.
9+
func AsBytes(s string) []byte {
10+
// get the pointer to the data of the string
11+
p := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data)
12+
13+
var b []byte
14+
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&b))
15+
hdr.Data = uintptr(p)
16+
// we need to set the cap and len for the string to byte convert
17+
// because string is shorter than []bytes
18+
hdr.Cap = len(s)
19+
hdr.Len = len(s)
20+
21+
// checker to check mutable access to the data
22+
SetChecker(b)
23+
return b
24+
}
25+
26+
// AsString returns a string that refers to the data backing the slice s.
27+
func AsString(b []byte) string {
28+
p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&b)).Data)
29+
30+
var s string
31+
hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
32+
hdr.Data = uintptr(p)
33+
hdr.Len = len(b)
34+
35+
// checker to check mutable access to the data
36+
SetChecker(b)
37+
return s
38+
}

ipc/interface.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ipc
2+
3+
import (
4+
"context"
5+
"os/exec"
6+
7+
"github.com/roadrunner-server/api/v2/worker"
8+
)
9+
10+
// Factory is responsible for wrapping given command into tasks WorkerProcess.
11+
type Factory interface {
12+
// SpawnWorkerWithTimeout creates new WorkerProcess process based on given command with context.
13+
// Process must not be started.
14+
SpawnWorkerWithTimeout(context.Context, *exec.Cmd) (worker.BaseProcess, error)
15+
// SpawnWorker creates new WorkerProcess process based on given command.
16+
// Process must not be started.
17+
SpawnWorker(*exec.Cmd) (worker.BaseProcess, error)
18+
// Close the factory and underlying connections.
19+
Close() error
20+
}

payload/payload.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package payload
2+
3+
import (
4+
"github.com/roadrunner-server/api/v2/internal"
5+
)
6+
7+
// Payload carries binary header and body to stack and
8+
// back to the server.
9+
type Payload struct {
10+
// Context represent payload context, might be omitted.
11+
Context []byte
12+
13+
// body contains binary payload to be processed by WorkerProcess.
14+
Body []byte
15+
16+
// Type of codec used to decode/encode payload
17+
Codec byte
18+
}
19+
20+
// String returns payload body as string
21+
func (p *Payload) String() string {
22+
return internal.AsString(p.Body)
23+
}

plugins/informer/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/roadrunner-server/api/v2/plugins/jobs"
7-
"github.com/roadrunner-server/sdk/v2/state/process"
7+
"github.com/roadrunner-server/api/v2/state/process"
88
)
99

1010
// Statistic interfaces ==============

plugins/jobs/interface.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/roadrunner-server/api/v2/plugins/jobs/pipeline"
7-
priorityqueue "github.com/roadrunner-server/sdk/v2/priority_queue"
7+
"github.com/roadrunner-server/api/v2/pq"
88
)
99

1010
// Consumer represents a single jobs driver interface
@@ -38,6 +38,6 @@ type Acknowledger interface {
3838

3939
// Constructor constructs Consumer interface. Endure abstraction.
4040
type Constructor interface {
41-
ConsumerFromConfig(configKey string, queue priorityqueue.Queue) (Consumer, error)
42-
ConsumerFromPipeline(pipe *pipeline.Pipeline, queue priorityqueue.Queue) (Consumer, error)
41+
ConsumerFromConfig(configKey string, queue pq.Queue) (Consumer, error)
42+
ConsumerFromPipeline(pipe *pipeline.Pipeline, queue pq.Queue) (Consumer, error)
4343
}

0 commit comments

Comments
 (0)