Skip to content
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
35 changes: 0 additions & 35 deletions .github/workflows/go.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
run: go build -v ./...

- name: Test
run: source pg_env && go test -p=1 -count=1 -failfast -coverprofile=coverage.txt -coverpkg=github.com/qor5/... ./...
run: source pg_env && go test -p=1 -count=1 -failfast -coverprofile=coverage.txt -coverpkg=github.com/qor5/... ./...
1 change: 1 addition & 0 deletions bm/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
version: '3.7'

services:
postgres:
image: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U adex" ]
interval: 1s
timeout: 5s
retries: 5
start_period: 5s
restart: always
environment:
POSTGRES_USER: myuser
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/golang/mock v1.4.3
github.com/lib/pq v1.3.0
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1
gopkg.in/yaml.v2 v2.3.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
18 changes: 16 additions & 2 deletions pg/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package pg
import (
"context"
"database/sql"
"fmt"
"time"

"github.com/pkg/errors"
"github.com/qor5/go-que"
)

Expand Down Expand Up @@ -106,7 +108,7 @@ func (j *job) Expire(ctx context.Context, cerr error) error {
var errMsg, errStack string
if cerr != nil {
errMsg = cerr.Error()
errStack = que.Stack(4)
errStack = getErrorStack(cerr)
}

_, err := j.exec(j.tx)(ctx, execSQL, errMsg, errStack, j.id)
Expand All @@ -125,7 +127,7 @@ func (j *job) RetryAfter(ctx context.Context, interval time.Duration, cerr error
var errMsg, errStack string
if cerr != nil {
errMsg = cerr.Error()
errStack = que.Stack(4)
errStack = getErrorStack(cerr)
}
_, err := j.exec(j.tx)(ctx, retryJob, intervalSeconds, errMsg, errStack, j.id)
return err
Expand All @@ -145,3 +147,15 @@ func (j *job) exec(tx *sql.Tx) func(context.Context, string, ...interface{}) (sq
}
return j.db.ExecContext
}

func getErrorStack(err error) string {
if err == nil {
return ""
}
if _, ok := err.(interface {
StackTrace() errors.StackTrace
}); ok {
return fmt.Sprintf("%+v", err)
}
return que.Stack(5)
}
5 changes: 5 additions & 0 deletions scheduler/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"io"
"io/ioutil"
"os"
"strings"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

Expand All @@ -28,6 +30,9 @@ type FileProvider struct {
}

func (fp *FileProvider) Provide() (Schedule, error) {
if strings.Contains(fp.Filename, "../") || strings.Contains(fp.Filename, "..\\") {
return nil, errors.Errorf("Invalid file path: %s", fp.Filename)
}
file, err := os.Open(fp.Filename)
if err != nil {
return nil, err
Expand Down