Larkspur Docs

Getting Started

This guide walks you through installing Larkspur, defining a handler and running your first worker.

1. Install

Go

go get github.com/larkspur-dev/larkspur/v2@latest

Python

pip install larkspur==2.4.1

Standalone worker binary

curl -fsSL https://get.larkspur.dev | sh
larkspur version
# larkspur 2.4.1 (linux/amd64)

2. Create a configuration file

# larkspur.toml
[store]
driver = "sqlite"
dsn    = "file:larkspur.db?_journal=WAL"

[worker]
concurrency = 8
poll_interval = "500ms"
visibility_timeout = "5m"

3. Define a handler

package main

import (
    "context"
    "log"

    "github.com/larkspur-dev/larkspur/v2"
)

type SendEmail struct {
    To      string `json:"to"`
    Subject string `json:"subject"`
}

func main() {
    q, err := larkspur.Open("larkspur.toml")
    if err != nil {
        log.Fatal(err)
    }
    larkspur.Handle(q, "emails", func(ctx context.Context, job SendEmail) error {
        log.Printf("sending %q to %s", job.Subject, job.To)
        return nil
    })
    log.Fatal(q.Run(context.Background()))
}

4. Enqueue a job

q.Enqueue(ctx, "emails", SendEmail{To: "ada@example.com", Subject: "Welcome"},
    larkspur.WithMaxAttempts(5),
    larkspur.WithDelay(30*time.Second))

Or from the command line:

larkspur enqueue emails '{"to":"ada@example.com","subject":"Welcome"}'

5. Inspect the queue

larkspur stats
QUEUE    READY  LEASED  FAILED  DONE(24h)
emails       0       0       0          1

Next, read the configuration reference or explore the HTTP API.