relay-sdk-go

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT

README

relay-sdk-go

GoDoc License

Relay SDK containing Go types, primitives, Client and Poller/consumer.

Requirements

  • Go 1.21+

Usage

See example here.

processor example.

package main

import (
	"context"
	"fmt"
	. "github.com/go-playground/pkg/v5/values/option"
	"github.com/relay-io/relay-sdk-go/core/job"
	"github.com/relay-io/relay-sdk-go/http/client"
)

type payload struct {
	CustomerID string `json:"customer_id"`
}

type state struct {
	Processed int `json:"processed"`
	Offset    int `json:"offset"`
}

var _ client.Runner[payload, state] = (*Processor)(nil)

type Processor struct {
}

func (p *Processor) Run(ctx context.Context, helper client.JobHelper[payload, state]) {
	// to something with job & state
	job := helper.Job()
	state := job.State.UnwrapOrDefault()
	fmt.Println(job, state)

	err := helper.Complete(ctx)
	if err != nil {
		panic(err)
	}
}

func main() {
	ctx := context.Background()

	relayClient := client.NewBuilder[payload, state]("http://localhost:8080").Build()
	queue := "my-queue"
	err := relayClient.Enqueue(ctx, job.Unique, []job.New[payload, state]{
		{
			Queue:      queue,
			ID:         "unique-queues-job-id",
			Timeout:    30,
			MaxRetries: None[int16](),
			Payload: payload{
				CustomerID: "unique-customer-account-id",
			},
			State: Some(state{
				Processed: 0,
				Offset:    0,
			}),
		},
	})
	if err != nil {
		panic(err)
	}

	poller := relayClient.Poller(queue, new(Processor)).NumWorkers(5).Build()
	if err != nil {
		panic(err)
	}

	err = poller.Start(ctx)
	if err != nil {
		panic(err)
	}
}

How to Contribute

Make a pull request...

License

Distributed under MIT License, please

Directories

Path Synopsis
_examples
core
job
http

Jump to

Keyboard shortcuts

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