Skip to content

Commit

Permalink
Merge pull request #23 from ripienaar/lint_docs
Browse files Browse the repository at this point in the history
(misc) address go lint issue and some docs
  • Loading branch information
ripienaar authored Feb 2, 2022
2 parents eada9ca + cbb6367 commit c2197fb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ This package heavily inspired by [hibiken/asynq](https://github.com/hibiken/asyn

* [Status](#status)
* [Features](#features)
* [Examples](https://github.com/choria-io/asyncjobs/blob/main/client_examples_test.go)
* [Examples](https://github.com/choria-io/asyncjobs/wiki/Introductory-Golang-Walkthrough)

[![Go Reference](https://pkg.go.dev/badge/github.com/choria-io/asyncjobs.svg)](https://pkg.go.dev/github.com/choria-io/asyncjobs)
[![Go Report Card](https://goreportcard.com/badge/github.com/choria-io/asyncjobs)](https://goreportcard.com/report/github.com/choria-io/asyncjobs)
[![CodeQL](https://github.com/choria-io/asyncjobs/workflows/CodeQL/badge.svg)](https://goreportcard.com/report/github.com/choria-io/asyncjobs)
[![CodeQL](https://github.com/choria-io/asyncjobs/workflows/CodeQL/badge.svg)](https://github.com/choria-io/asyncjobs/actions/workflows/codeql.yaml)
[![Unit Tests](https://github.com/choria-io/asyncjobs/actions/workflows/test.yaml/badge.svg)](https://github.com/choria-io/asyncjobs/actions/workflows/test.yaml)

## Status
Expand Down
16 changes: 10 additions & 6 deletions ajc/task_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,20 @@ func (c *taskCommand) viewAction(_ *kingpin.ParseContext) error {
fmt.Printf("Task %s created at %s\n\n", task.ID, task.CreatedAt.Format(timeFormat))
fmt.Printf(" Payload: %s\n", humanize.IBytes(uint64(len(task.Payload))))
fmt.Printf(" Status: %s\n", task.State)
if task.Result != nil {
fmt.Printf(" Completed: %s (%s)\n", task.Result.CompletedAt.Format(timeFormat), humanizeDuration(task.Result.CompletedAt.Sub(task.CreatedAt)))
} else {
if task.LastTriedAt != nil {
fmt.Printf(" Last Processed: %s\n", task.LastTriedAt.Format(timeFormat))
}
if task.LastErr != "" {
fmt.Printf(" Last Error: %s\n", task.LastErr)
}
}
if task.Queue != "" {
fmt.Printf(" Queue: %s\n", task.Queue)
}
fmt.Printf(" Tries: %d\n", task.Tries)
if task.LastTriedAt != nil {
fmt.Printf(" Last Processed: %s\n", task.LastTriedAt.Format(timeFormat))
}
if task.LastErr != "" {
fmt.Printf(" Last Error: %s\n", task.LastErr)
}
if task.Deadline != nil {
fmt.Printf(" Scheduling Deadline: %s\n", task.Deadline.Format(timeFormat))
}
Expand Down
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
ErrTerminateTask = fmt.Errorf("terminate task")
)

// Storage implements the backend access
type Storage interface {
SaveTaskState(ctx context.Context, task *Task) error
EnqueueTask(ctx context.Context, queue *Queue, task *Task) error
Expand Down Expand Up @@ -139,6 +140,7 @@ func (c *Client) EnqueueTask(ctx context.Context, task *Task) error {
return c.opts.queue.enqueueTask(ctx, task)
}

// StorageAdmin access admin features of the storage backend
func (c *Client) StorageAdmin() StorageAdmin {
return c.storage
}
Expand All @@ -165,13 +167,16 @@ func nowPointer() *time.Time {
func (c *Client) setTaskActive(ctx context.Context, t *Task) error {
t.State = TaskStateActive
t.LastTriedAt = nowPointer()
t.LastErr = ""

return c.storage.SaveTaskState(ctx, t)
}

func (c *Client) setTaskSuccess(ctx context.Context, t *Task, payload interface{}) error {
t.LastTriedAt = nowPointer()
t.State = TaskStateCompleted
t.LastErr = ""

t.Result = &TaskResult{
Payload: payload,
CompletedAt: time.Now().UTC(),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.2
github.com/dustin/go-humanize v1.0.0
github.com/nats-io/jsm.go v0.0.28-0.20220128163911-90cd1007b323
github.com/nats-io/nats-server/v2 v2.7.2-0.20220131171338-74c0fdc3bb8b
github.com/nats-io/nats-server/v2 v2.7.2-0.20220201222209-2ed7a812d8b2
github.com/nats-io/nats.go v1.13.1-0.20220121202836-972a071d373d
github.com/onsi/ginkgo/v2 v2.1.0
github.com/onsi/gomega v1.17.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ github.com/nats-io/nats-server/v2 v2.7.2-0.20220130232407-6b690bd5b635 h1:h6+xCw
github.com/nats-io/nats-server/v2 v2.7.2-0.20220130232407-6b690bd5b635/go.mod h1:tckmrt0M6bVaDT3kmh9UrIq/CBOBBse+TpXQi5ldaa8=
github.com/nats-io/nats-server/v2 v2.7.2-0.20220131171338-74c0fdc3bb8b h1:h8EYD8Q7yUbjXmMT6z1XI7SAV+aiHhkNEc1O+WImMh4=
github.com/nats-io/nats-server/v2 v2.7.2-0.20220131171338-74c0fdc3bb8b/go.mod h1:tckmrt0M6bVaDT3kmh9UrIq/CBOBBse+TpXQi5ldaa8=
github.com/nats-io/nats-server/v2 v2.7.2-0.20220201222209-2ed7a812d8b2 h1:/ocgZt+pxx9ocGWWdeBAJfg0tqoz4uUoIgCNepKnnDQ=
github.com/nats-io/nats-server/v2 v2.7.2-0.20220201222209-2ed7a812d8b2/go.mod h1:tckmrt0M6bVaDT3kmh9UrIq/CBOBBse+TpXQi5ldaa8=
github.com/nats-io/nats.go v1.13.1-0.20220121202836-972a071d373d h1:GRSmEJutHkdoxKsRypP575IIdoXe7Bm6yHQF6GcDBnA=
github.com/nats-io/nats.go v1.13.1-0.20220121202836-972a071d373d/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w=
github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
Expand Down

0 comments on commit c2197fb

Please sign in to comment.