-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impl pagination, split exec log out of task list
- Loading branch information
Showing
22 changed files
with
6,604 additions
and
6,762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
ROOT_DIR := $(shell pwd) | ||
|
||
MAIN_PACKAGE_PATH ?= ./ | ||
BINARY_NAME ?= ap-avs | ||
BINARY_NAME ?= ap | ||
|
||
# ==================================================================================== # | ||
# HELPERS | ||
|
@@ -56,15 +58,6 @@ build: | |
run: build | ||
/tmp/bin/${BINARY_NAME} | ||
|
||
## run/live: run the application with reloading on file changes | ||
.PHONY: run/live | ||
run/live: | ||
go run github.com/cosmtrek/[email protected] \ | ||
--build.cmd "make build" --build.bin "/tmp/bin/${BINARY_NAME}" --build.delay "100" \ | ||
--build.exclude_dir "" \ | ||
--build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \ | ||
--misc.clean_on_exit "true" | ||
|
||
|
||
## push: push changes to the remote Git repository | ||
.PHONY: push | ||
|
@@ -77,14 +70,22 @@ production/deploy: confirm tidy audit no-dirty | |
GOOS=linux GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/linux_amd64/${BINARY_NAME} ${MAIN_PACKAGE_PATH} | ||
upx -5 /tmp/bin/linux_amd64/${BINARY_NAME} | ||
|
||
## dev: generate protoc | ||
## protoc-gen: generate protoc buf Go binding | ||
.PHONY: protoc-gen | ||
protoc-gen: | ||
protoc \ | ||
--go_out=. \ | ||
--go_opt=paths=source_relative \ | ||
--go-grpc_out=. \ | ||
--go-grpc_opt=paths=source_relative \ | ||
protobuf/avs.proto | ||
protobuf/avs.proto | ||
|
||
protoc \ | ||
--go_out=. \ | ||
--go_opt=paths=source_relative \ | ||
--go-grpc_out=. \ | ||
--go-grpc_opt=paths=source_relative \ | ||
protobuf/node.proto | ||
|
||
## up: bring up docker compose stack | ||
up: | ||
|
@@ -96,6 +97,15 @@ unstable-build: | |
docker push avaprotocol/avs-dev:unstable | ||
|
||
|
||
## dev/live: run the application with reloading on file changes | ||
.PHONY: dev-live | ||
dev-live: | ||
go run github.com/air-verse/[email protected] \ | ||
--build.cmd "make dev-build" --build.bin "./out/${BINARY_NAME}" --build.args_bin "aggregator" --build.delay "100" \ | ||
--build.exclude_dir "certs,client-sdk,contracts,examples,out,docs,tmp" \ | ||
--build.include_ext "go, tpl, tmpl, html, css, scss, js, ts, sql, jpeg, jpg, gif, png, bmp, svg, webp, ico" \ | ||
--misc.clean_on_exit "true" | ||
|
||
## dev-build: build a dev version for local development | ||
dev-build: | ||
mkdir out || true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package taskengine | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"strconv" | ||
|
||
"github.com/oklog/ulid/v2" | ||
) | ||
|
||
type CursorDirection string | ||
|
||
const ( | ||
CursorDirectionNext = CursorDirection("next") | ||
CursorDirectionPrevious = CursorDirection("prev") | ||
) | ||
|
||
type Cursor struct { | ||
Direction CursorDirection `json:"d"` | ||
Position string `json:"p"` | ||
|
||
parsePos bool `json:"-"` | ||
int64Pos int64 `json:"-"` | ||
ulidPos ulid.ULID `json:"-"` | ||
} | ||
|
||
func CursorFromString(data string) (*Cursor, error) { | ||
c := &Cursor{ | ||
Direction: CursorDirectionNext, | ||
Position: "0", | ||
parsePos: false, | ||
int64Pos: 0, | ||
ulidPos: ulid.Zero, | ||
} | ||
|
||
decoded, err := base64.StdEncoding.DecodeString(data) | ||
if err != nil { | ||
return c, err | ||
} | ||
|
||
if err = json.Unmarshal(decoded, &c); err == nil { | ||
return c, nil | ||
} else { | ||
return c, err | ||
} | ||
} | ||
|
||
func NewCursor(direction CursorDirection, position string) *Cursor { | ||
return &Cursor{ | ||
Direction: direction, | ||
Position: position, | ||
|
||
parsePos: false, | ||
int64Pos: 0, | ||
} | ||
} | ||
func (c *Cursor) String() string { | ||
var d []byte | ||
d, err := json.Marshal(c) | ||
|
||
if err != nil { | ||
return "" | ||
} | ||
|
||
encoded := base64.StdEncoding.EncodeToString(d) | ||
|
||
return encoded | ||
} | ||
|
||
// Given a value, return true if the value is after the cursor | ||
func (c *Cursor) AfterInt64(value int64) bool { | ||
if !c.parsePos { | ||
c.int64Pos, _ = strconv.ParseInt(c.Position, 10, 64) | ||
c.parsePos = true | ||
} | ||
if c.Direction == CursorDirectionNext { | ||
return c.int64Pos <= value | ||
} | ||
|
||
return c.int64Pos >= value | ||
} | ||
|
||
// Given a value, return true if the value is after the cursor | ||
func (c *Cursor) AfterUlid(value ulid.ULID) bool { | ||
if !c.parsePos { | ||
var err error | ||
c.ulidPos, err = ulid.Parse(c.Position) | ||
if err != nil { | ||
c.ulidPos = ulid.Zero | ||
} | ||
c.parsePos = true | ||
} | ||
if c.Direction == CursorDirectionNext { | ||
return c.ulidPos.Compare(value) < 0 | ||
} | ||
return c.ulidPos.Compare(value) > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.