stateful-retrier

command module
v0.0.0-...-d8aa408 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 8 Imported by: 0

README

Stateful retrier

Implementation of transactional outbox pattern in Go.

Purpose

This is a simple implementation of a stateful retrier. The stateful retrier is like durable functions. It retries the operation until it succeeds. It uses Postgres to store the state of the operation.

Prerequisites

  • Docker
  • Golang 1.21

How to run

docker-compose up

go run .

Usage


func main() {
    db, err := pgxpool.New("postgres", "dsn")
    if err != nil {
        log.Fatal(err)
    }

    // Setup terminator, it would terminate the task after 5 retries or 24 hours
    terminator := NewTerminator(5, 24 * time.Hour)

    retrier := NewStatefulRetrier(db, terminator)

    // Init worker
    worker := NewWorker(db)
	
    // Register function
    worker.RegisterFunction(MyFunctionKey, myFunction.Execute)

    // Start worker
    retrier.ScheduleTask(MyFunctionKey, myPayload)

    for {
        worker.ProcessTasks()
        time.Sleep(1 * time.Minute)
    }
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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