Skip to content

Commit

Permalink
Merge pull request #46 from zengzhengrong/fix45
Browse files Browse the repository at this point in the history
Fix45
  • Loading branch information
fieldryand authored Jan 13, 2024
2 parents 1080c0a + 28bd883 commit 4facc37
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ goflow.db

# The test database
test.db
.vscode
5 changes: 3 additions & 2 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
func complexAnalyticsJob() *Job {
j := &Job{
Name: "exampleComplexAnalytics",
Schedule: "* * * * *",
Schedule: "* * * * * *",
Active: false,
}

j.Add(&Task{
Expand Down Expand Up @@ -82,7 +83,7 @@ func (o PositiveAddition) Run() (interface{}, error) {

// Use our custom operation in a job.
func customOperatorJob() *Job {
j := &Job{Name: "exampleCustomOperator", Schedule: "* * * * *", Active: true}
j := &Job{Name: "exampleCustomOperator", Schedule: "* * * * * *", Active: true}
j.Add(&Task{Name: "posAdd", Operator: PositiveAddition{5, 6}})
return j
}
5 changes: 4 additions & 1 deletion example/goflow-example.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import "github.com/fieldryand/goflow/v2"
import (
"github.com/fieldryand/goflow/v2"
)

func main() {
options := goflow.Options{
UIPath: "ui/",
Streaming: true,
ShowExamples: true,
WithSeconds: true,
}
gf := goflow.New(options)
gf.Use(goflow.DefaultLogger())
Expand Down
9 changes: 8 additions & 1 deletion goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,28 @@ type Options struct {
UIPath string
Streaming bool
ShowExamples bool
WithSeconds bool
}

// New returns a Goflow engine.
func New(opts Options) *Goflow {
var c *cron.Cron
if opts.Store == nil {
opts.Store = gomap.NewStore(gomap.DefaultOptions)
}
defer opts.Store.Close()
if opts.WithSeconds {
c = cron.New(cron.WithSeconds())
} else {
c = cron.New()
}

g := &Goflow{
Store: opts.Store,
Options: opts,
Jobs: make(map[string](func() *Job)),
router: gin.New(),
cron: cron.New(),
cron: c,
activeJobCronIDs: make(map[string]cron.EntryID),
}

Expand Down

0 comments on commit 4facc37

Please sign in to comment.