tasks

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package taskqueue provides a durable task client for Hanzo Tasks.

Drop-in replacement for Base's Cron():

// Before (cron):
e.App.Cron().Add("settlement", "*/30 * * * * *", func() { ... })

// After (tasks):
tasks.Add("settlement", "30s", func() { ... })

If TASKS_URL is set, schedules run as durable Temporal workflows (retries, dead letter, audit trail). If not, runs locally via goroutine timer (dev mode, same behavior as cron but no persistence).

Package sdk provides the Hanzo Tasks client for Go applications.

Two methods, two use cases:

client := sdk.New(os.Getenv("TASKS_URL"), nil)
client.Add("settlement.process", "30s", fn)   // recurring schedule
client.Now("webhook.deliver", payload)          // fire once immediately

When TASKS_URL is set, tasks execute as durable Temporal workflows with retry, dead letter, and audit trail. When empty, tasks run locally via goroutine timers (dev mode).

Integration with Hanzo Base:

app.Tasks().Add("cleanup", "1h", fn)
app.Tasks().Now("email.send", payload)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages both one-shot tasks and recurring schedules.

func New

func New(tasksURL string, handler Handler) *Client

New creates a Client. If tasksURL is empty, everything runs locally.

func (*Client) Add

func (c *Client) Add(name, interval string, fn func()) error

Add registers a recurring task. interval is a duration string ("30s", "5m", "1h"). The fn runs every interval. If TASKS_URL is set, creates a durable Temporal schedule. Otherwise runs a local ticker (same as cron but cleaner).

tasks.Add("settlement.process", "30s", func() { processSettlements() })
tasks.Add("oracle.update", "5m", func() { updateOracle() })

func (*Client) Now

func (c *Client) Now(taskType string, payload map[string]any) error

Enqueue submits a one-shot task for durable execution.

func (*Client) Stop

func (c *Client) Stop()

Stop cancels all local schedules. Call on shutdown.

type Handler

type Handler func(taskType string, payload map[string]any)

Handler processes a one-shot task (webhook delivery, settlement, etc.)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL