Skip to content

Commit

Permalink
Merge pull request #62 from fieldryand/fix-storage-bug
Browse files Browse the repository at this point in the history
Fix premature closing of the store client
  • Loading branch information
fieldryand authored Feb 4, 2024
2 parents 2f32b7d + fad7946 commit 558a3f9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
18 changes: 18 additions & 0 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# for testing goflow-example-postgres.go
version: '3.1'

services:

db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: example
ports:
- 5432:5432

adminer:
image: adminer
restart: always
ports:
- 8080:8080
32 changes: 32 additions & 0 deletions example/goflow-example-postgres.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

//import (
// "github.com/fieldryand/goflow/v2"
// "github.com/philippgille/gokv/encoding"
// "github.com/philippgille/gokv/postgresql"
//)
//
//func main() {
// storeOptions := postgresql.Options{
// ConnectionURL: "postgres://postgres:example@0.0.0.0:5432/postgres?sslmode=disable",
// TableName: "Item",
// MaxOpenConnections: 100,
// Codec: encoding.JSON,
// }
//
// client, err := postgresql.NewClient(storeOptions)
// if err != nil {
// panic(err)
// }
// defer client.Close()
//
// options := goflow.Options{
// Store: client,
// Streaming: true,
// ShowExamples: true,
// WithSeconds: true,
// }
// gf := goflow.New(options)
// gf.Use(goflow.DefaultLogger())
// gf.Run(":8181")
//}
7 changes: 5 additions & 2 deletions goflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ type Options struct {

// New returns a Goflow engine.
func New(opts Options) *Goflow {
var c *cron.Cron

// Add a default store if necessary
if opts.Store == nil {
opts.Store = gomap.NewStore(gomap.DefaultOptions)
}
defer opts.Store.Close()

// Add the cron schedule
var c *cron.Cron
if opts.WithSeconds {
c = cron.New(cron.WithSeconds())
} else {
Expand Down

0 comments on commit 558a3f9

Please sign in to comment.