X Tutup
The Wayback Machine - https://web.archive.org/web/20201231203145/https://github.com/ioj/gophile-worker
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

gophile-worker

GoDoc Go Report Card License

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.

About

A simple task runner compatible with graphile-worker

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.
X Tutup