gophile-worker
A simple task runner compatible with graphile-worker — if you prefer to run your background tasks with Go instead of Nodejs.
Quickstart
Create a test database
createdb worker_test
Install graphile-worker schema
npx graphile-worker -c "worker_test" --schema-only
Implement a simple task runner
package main
import (
"context"
"fmt"
"log"
worker "github.com/ioj/gophile-worker"
)
type HelloPayload struct {
Name string `json:"name"`
}
func main() {
w := worker.New(nil)
w.Handle("hello", func(ctx context.Context, job *worker.Job) error {
p := HelloPayload{}
if err := job.UnmarshalPayload(&p); err != nil {
return err
}
if p.Name == "" {
p.Name = "stranger"
}
fmt.Printf("Hello, %v!\n", p.Name)
return nil
})
conninfo := "dbname=worker_test sslmode=disable"
log.Fatal(w.ListenAndServe(conninfo))
}Schedule a job via SQL
SELECT graphile_worker.add_job('hello', json_build_object('name', 'Bobby Tables'));You should see the worker output Hello, Bobby Tables!
What's next?
Please take a look at Documentation and a more elaborate example, which shows how to use middleware and handle graceful shutdown.
License
This library is distributed under the terms of the MIT License. See the included file for more detail.
Contributing
All suggestions and patches welcome, preferably via a git repository I can pull from. If this library proves useful to you, please let me know.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
