downstream

package
v0.0.0-...-7ed8402 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

A client for a downstream HTTP service that can do work.

Once the dequeuer takes jobs out of the database, it needs to do some work and then report whether the work was successful or not. We do this by making a HTTP request to a downstream service that doesn't have any state built in, it just performs work when it's told to do so.

This package contains a client for making requests to that downstream service. For example usage, check the example in this file or JobProcessor in the services package.

Example

Create a new client, then make a request to a downstream service with an empty data object.

client := NewClient("test", "hymanrickover", "http://downstream-server.example.com")
params := JobParams{
	Data:     json.RawMessage([]byte("{}")),
	Attempts: 3,
}
id, _ := types.NewPrefixUUID("job_123")
client.Job.Post(context.TODO(), "invoice-shipment", &id, &params)
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var Logger *log.Logger

Functions

This section is empty.

Types

type Client

type Client struct {
	*restclient.Client

	Job *JobService
}

The DownstreamClient is an API client for a downstream service that can handle POST requests to /v1/jobs/:job-name/:job-id. The service is expected to return a 202 and then make a callback to the job scheduler when the job has finished running.

func NewClient

func NewClient(id, token, base string) *Client

NewClient creates a new Client.

type JobParams

type JobParams struct {
	Data     json.RawMessage `json:"data"`
	Attempts int16           `json:"attempts"`
}

type JobService

type JobService struct {
	Client *Client
}

func (*JobService) Post

func (j *JobService) Post(ctx context.Context, name string, id *types.PrefixUUID, jp *JobParams) error

Post makes a request to /v1/jobs/:job-name/:job-id with the job data. The downstream service is expected to respond with a 202, so there is no positive return value, only nil if the response was a 2xx status code.

Directories

Path Synopsis
The downstream-server is a Go server that can dequeue jobs and hit the callback.
The downstream-server is a Go server that can dequeue jobs and hit the callback.

Jump to

Keyboard shortcuts

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