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

v3.0.1 #89

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 10 additions & 16 deletions .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
REGISTRY: ghcr.io
IMAGE_NAME: fieldryand/goflow-example
IMAGE_NAME: fieldryand/goflow-example-simple

jobs:
build-and-push-image:
Expand All @@ -23,37 +23,31 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'

- name: Set up Node
uses: actions/setup-node@v2

- name: Compile UI
run: cd ui && npm install && npm run build

- name: Build goflow-example
run: go build example/goflow-example.go
- name: Build goflow-example-simple
run: go build examples/simple/goflow-example-simple.go

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand All @@ -64,6 +58,6 @@ jobs:
run: tar -czvf goflow-ui.tar.gz ui

- name: Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: goflow-ui.tar.gz
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [ main, v3 ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.22'

- name: Test
run: go test ./... -coverprofile=coverage.txt -race
run: go test -coverprofile=coverage.txt -race

- name: Codecov
uses: codecov/codecov-action@v3
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
Expand All @@ -26,7 +26,7 @@ jobs:
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# args: --exclude-dirs examples

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
Expand Down
23 changes: 8 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# Output of the go test coverage tool
*.out

# The goflow-example binary
goflow-example

# Front-end dependencies
ui/node_modules

# Front-end compiled assets
ui/dist

# The default goflow database
goflow.db

# The test database
test.db
.vscode
# The goflow-example binaries
goflow-example-chained
goflow-example-simple
goflow-example-shutdown
goflow-example-store

# Example store
/gokv
3 changes: 0 additions & 3 deletions .golangci.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.56.2
rev: v1.62.0
hooks:
- id: golangci-lint
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ FROM centos
ENV GIN_MODE=release

WORKDIR /opt
COPY goflow-example goflow-example
COPY goflow-example-simple goflow-example-simple
COPY ui ui

EXPOSE 8181

CMD ["./goflow-example"]
CMD ["./goflow-example-simple"]
138 changes: 76 additions & 62 deletions example.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package goflow

import (
"context"
"errors"
"fmt"
"log"
"math/rand"
)

Expand All @@ -13,82 +16,93 @@ func complexAnalyticsJob() *Job {
Active: false,
}

j.Add(&Task{
Name: "sleep-one",
Operator: Command{Cmd: "sleep", Args: []string{"1"}},
})
j.Add(&Task{
Name: "add-one-one",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((1 + 1))"}},
})
j.Add(&Task{
Name: "sleep-two",
Operator: Command{Cmd: "sleep", Args: []string{"2"}},
})
j.Add(&Task{
Name: "add-two-four",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((2 + 4))"}},
})
j.Add(&Task{
Name: "add-three-four",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((3 + 4))"}},
})
j.Add(&Task{
Name: "whoops-with-constant-delay",
Operator: Command{Cmd: "whoops", Args: []string{}},
Retries: 5,
RetryDelay: ConstantDelay{Period: 1},
})
j.Add(&Task{
Name: "whoops-with-exponential-backoff",
Operator: Command{Cmd: "whoops", Args: []string{}},
Retries: 1,
RetryDelay: ExponentialBackoff{},
})
j.Add(&Task{
Name: "totally-skippable",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo 'everything succeeded'"}},
TriggerRule: "allSuccessful",
})
j.Add(&Task{
Name: "clean-up",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo 'cleaning up now'"}},
TriggerRule: "allDone",
})
err := j.AddTask(
&Task{
Name: "sleep-one",
Operator: Command{Cmd: "sleep", Args: []string{"1"}},
},
&Task{
Name: "add-one-one",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((1 + 1))"}},
},
&Task{
Name: "sleep-two",
Operator: Command{Cmd: "sleep", Args: []string{"2"}},
},
&Task{
Name: "add-two-four",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((2 + 4))"}},
},
&Task{
Name: "add-three-four",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo $((3 + 4))"}},
},
&Task{
Name: "whoops-with-constant-delay",
Operator: Command{Cmd: "whoops", Args: []string{}},
Retries: 5,
RetryDelay: ConstantDelay{Period: 1},
},
&Task{
Name: "whoops-with-exponential-backoff",
Operator: Command{Cmd: "whoops", Args: []string{}},
Retries: 1,
RetryDelay: ExponentialBackoff{},
},
&Task{
Name: "totally-skippable",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo 'everything succeeded'"}},
TriggerRule: "allSuccessful",
},
&Task{
Name: "clean-up",
Operator: Command{Cmd: "sh", Args: []string{"-c", "echo 'cleaning up now'"}},
TriggerRule: "allDone",
},
)

j.SetDownstream(j.Task("sleep-one"), j.Task("add-one-one"))
j.SetDownstream(j.Task("add-one-one"), j.Task("sleep-two"))
j.SetDownstream(j.Task("sleep-two"), j.Task("add-two-four"))
j.SetDownstream(j.Task("add-one-one"), j.Task("add-three-four"))
j.SetDownstream(j.Task("sleep-one"), j.Task("whoops-with-constant-delay"))
j.SetDownstream(j.Task("sleep-one"), j.Task("whoops-with-exponential-backoff"))
j.SetDownstream(j.Task("whoops-with-constant-delay"), j.Task("totally-skippable"))
j.SetDownstream(j.Task("whoops-with-exponential-backoff"), j.Task("totally-skippable"))
j.SetDownstream(j.Task("totally-skippable"), j.Task("clean-up"))
if err != nil {
log.Printf("error adding task: %v", err)
}

j.SetDownstream("sleep-one", "add-one-one")
j.SetDownstream("add-one-one", "sleep-two")
j.SetDownstream("sleep-two", "add-two-four")
j.SetDownstream("add-one-one", "add-three-four")
j.SetDownstream("sleep-one", "whoops-with-constant-delay")
j.SetDownstream("sleep-one", "whoops-with-exponential-backoff")
j.SetDownstream("whoops-with-constant-delay", "totally-skippable")
j.SetDownstream("whoops-with-exponential-backoff", "totally-skippable")
j.SetDownstream("totally-skippable", "clean-up")

return j
}

// RandomFailure fails randomly. This is a contrived example for demo purposes.
type RandomFailure struct{ n int }
// randomFailure fails randomly. This is a contrived example for demo purposes.
type randomFailure struct{ n int }

// rng with seed=1
var r = rand.New(rand.NewSource(1))

// Run implements failures at random intervals.
func (o RandomFailure) Run() (interface{}, error) {
func (o randomFailure) Run(ctx context.Context) (any, error) {
select {
case <-ctx.Done():
return nil, errors.New("context cancelled")
default:
}
x := r.Intn(o.n)

if x == o.n-1 {
return nil, errors.New("unlucky")
return "randomly failed", errors.New("unlucky")
}

return x, nil
return fmt.Sprintf("the result is %v", x), nil
}

// Use our custom operation in a job.
func customOperatorJob() *Job {
j := &Job{Name: "example-custom-operator", Schedule: "* * * * * *", Active: true}
j.Add(&Task{Name: "random-failure", Operator: RandomFailure{4}})
func randomFailureJob() *Job {
j := &Job{Name: "example-random-failure", Schedule: "* * * * * *", Active: true}
err := j.AddTask(&Task{Name: "random-failure", Operator: randomFailure{4}})
if err != nil {
log.Printf("error adding task: %v", err)
}
return j
}
18 changes: 0 additions & 18 deletions example/docker-compose.yml

This file was deleted.

32 changes: 0 additions & 32 deletions example/goflow-example-postgres.go

This file was deleted.

Loading
Loading