Categorygithub.com/cloudchacho/taskhawk-go
modulepackage
0.2.0
Repository: https://github.com/cloudchacho/taskhawk-go.git
Documentation: pkg.go.dev

# README

Taskhawk Go

Build Status Go Report Card Godoc codecov

Taskhawk is an async task execution framework (à la celery) that works on AWS and GCP, while keeping things pretty simple and straight forward. Any unbound function can be converted into a Taskhawk task.

Only Go 1.18+ is supported currently.

This project uses semantic versioning.

Quick Start

First, install the library:

go get github.com/cloudchacho/taskhawk-go

If your function takes multiple arguments, convert your function into a "Task" as shown here:

type SendEmailTaskInput struct {...}

func SendEmail(ctx context.Context, input *SendEmailTaskInput) error {
    // send email
}

Tasks may accept input of arbitrary pointer type as long as it's serializable to JSON. Remember to export fields!

Then, define your backend:

settings := aws.Settings{
    AWSAccessKey: <YOUR AWS ACCESS KEY>,
    AWSAccountID: <YOUR AWS ACCOUNT ID>,
    AWSRegion: <YOUR AWS REGION>,
    AWSSecretKey: <YOUR AWS SECRET KEY>,

    Queue: <YOUR TASKHAWK QUEUE>,
}
backend := aws.NewBackend(settings, nil)

Before the task can be dispatched, it would need to be registered, as shown below.

hub := NewHub(Config{...}, backend)
task, err := taskhawk.RegisterTask(hub, "SendEmailTask", SendEmailTask)

And finally, dispatch your task asynchronously:

task.dispatch(&SendEmailTaskInput{...})

Development

Prerequisites

Install go1.18.x

Getting Started

Assuming that you have golang installed, set up your environment like so:


$ cd ${GOPATH}/src/github.com/cloudchacho/taskhawk-go
$ go build

Running tests


$ make test  
# OR
$ go test -tags test ./...

Getting Help

We use GitHub issues for tracking bugs and feature requests.

  • If it turns out that you may have found a bug, please open an issue

Release notes

Current version: v0.2.0-dev

v0.1.0

  • Initial version

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
NewHub creates a hub.
RegisterTask registers the task to the hub with priority 'default'.
RegisterTaskWithPriority registers the task to the hub with specified priority.

# Constants

CurrentVersion represents the current version of the taskhawk message schema.
PriorityBulk queue will typically have different monitoring, and may be used for bulk jobs, such as sending push notifications to all users.
Keep default first so empty values automatically default.
Priority for a task.
Priority for a task.
Version10 represents the first version of the message format schema.

# Variables

ErrRetry should cause the task to retry, but not treat the retry as an error.
ErrTaskNotFound indicates that task was not found.

# Structs

Config used to configure Taskhawk Hub.
Hub is the central struct used to dispatch Taskhawk tasks / run consumer.
ListenRequest represents a request to listen for messages.
ReceivedMessage is the message as received by a transport backend.
No description provided by the author
No description provided by the author

# Interfaces

ConsumerBackend is used for consuming messages from a transport.
HeadersCarrier interface needs to be implemented by the input struct if your task needs to get custom headers set during dispatch.
Instrumenter defines the interface for Taskhawk's instrumentation.
Logger represents an logging interface that this library expects.
MetadataSetter interface needs to be implemented by the input struct if your task needs to get metatada ( message id etc).
PublisherBackend is used to publish messages to a transport.

# Type aliases

GetLoggerFunc returns the logger object.
No description provided by the author
Priority of a task.
No description provided by the author
Version represents the message format version.