corejobs

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

README

Core Jobs

This package defines job types used by the Openlane API (core) with Riverqueue. Due to cyclical dependency issues, any job that uses the openlane API, needs to be defined in this repo, and just configured in riverboat.

Usage

  1. Add new jobs to this directory in a new file, refer to the upstream docs for implementation details. The following is a stem job that could be copied to get you started.

    package jobs
    
    import (
       "context"
    
       "github.com/riverqueue/river"
       "github.com/rs/zerolog/log"
    )
    
    // ExampleArgs for the example worker to process the job
    type ExampleArgs struct {
       // ExampleArg is an example argument
       ExampleArg string `json:"example_arg"`
    }
    
    // Kind satisfies the river.Job interface
    func (ExampleArgs) Kind() string { return "example" }
    
    // ExampleWorker does all sorts of neat stuff
    type ExampleWorker struct {
       river.WorkerDefaults[ExampleArgs]
    
       ExampleConfig
    }
    
    // ExampleConfig contains the configuration for the example worker
    type ExampleConfig struct {
       // DevMode is a flag to enable dev mode so we don't actually send millions of carrier pigeons
       DevMode bool `koanf:"devMode" json:"devMode" jsonschema:"description=enable dev mode" default:"true"`
    }
    
    // Work satisfies the river.Worker interface for the example worker
    func (w *ExampleConfig) Work(ctx context.Context, job *river.Job[ExampleArgs]) error {
       // do some work
    
       return nil
    }
    
  2. Add a test for the new job. There are additional helper functions that can be used, see river test helpers for details.

  3. Add a test job to test/ directory by creating a new directory with a main.go function that will insert the job into the queue.

  4. Workers should be registered in the riverboat

Test Jobs

Included in the test/ directory are test jobs corresponding to the job types in pkg/jobs.

  1. Start the riverboat server using task run-dev

  2. Run the test main, for example the email:

    go run test/email/main.go
    
  3. This should insert the job successfully, it should be processed by river and the email should be added to fixtures/email

Contributing

See the contributing guide for more information.

Documentation

Overview

Package corejobs holds jobs definitions for riverqueue that interact with the core api

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedStatus is returned when an HTTP request returns a status code other than 200
	ErrUnexpectedStatus = errors.New("unexpected HTTP status")
	// ErrGraphQLMessage is returned when an error message exists in the response
	ErrGraphQLMessage = errors.New("GraphQL error")
	// ErrUnknownGraphQLError is returned when an GraphQL error occurs but no specific message is available
	ErrUnknownGraphQLError = errors.New("an unknown error occurred")
	// ErrMissingRoot is returned when the GraphQL response is missing the expected root field
	ErrMissingRoot = errors.New("missing root in response")
	// ErrMissingEdges is returned when the response is missing the edges field expected for the data
	ErrMissingEdges = errors.New("missing edges in response")
	// ErrMissingPageInfo is returned when the response is missing pagination data
	ErrMissingPageInfo = errors.New("missing pageInfo in response")
	// ErrMissingHasNextPage is returned when pagination data is missing the hasNextPage field
	ErrMissingHasNextPage = errors.New("missing hasNextPage in pageInfo")
	// ErrMissingEndCursor is returned when pagination data is missing the endCursor field needed for pagination
	ErrMissingEndCursor = errors.New("missing endCursor in pageInfo")
)
View Source
var (
	// ErrDomainVerificationAlreadyExists is returned when a custom domain already has a verification member
	ErrDomainVerificationAlreadyExists = errors.New("custom domain already has a verification member")
)

Functions

This section is empty.

Types

type CreateCustomDomainArgs

type CreateCustomDomainArgs struct {
	// ID of the custom domain in our system
	CustomDomainID string `json:"custom_domain_id"`
}

CreateCustomDomainArgs for the worker to process the custom domain

func (CreateCustomDomainArgs) Kind

Kind satisfies the river.Job interface

type CreateCustomDomainWorker

type CreateCustomDomainWorker struct {
	river.WorkerDefaults[CreateCustomDomainArgs]

	Config CustomDomainConfig
	// contains filtered or unexported fields
}

CreateCustomDomainWorker creates a custom hostname in cloudflare, and creates and updates the records in our system

func (*CreateCustomDomainWorker) WithCloudflareClient

WithCloudflareClient sets the Cloudflare client for the worker and returns the worker for method chaining

func (*CreateCustomDomainWorker) WithOpenlaneClient

WithOpenlaneClient sets the Openlane client for the worker and returns the worker for method chaining

func (*CreateCustomDomainWorker) WithRiverClient

WithRiverClient sets the River client for the worker and returns the worker for method chaining

func (*CreateCustomDomainWorker) Work

Work satisfies the river.Worker interface for the create custom domain worker it creates a custom domain for an organization

type CustomDomainConfig

type CustomDomainConfig struct {
	CloudflareAPIKey string `koanf:"cloudflareApiKey" json:"cloudflareApiKey" jsonschema:"required description=the cloudflare api key"`

	OpenlaneAPIHost  string `koanf:"openlaneAPIHost" json:"openlaneAPIHost" jsonschema:"required description=the openlane api host"`
	OpenlaneAPIToken string `koanf:"openlaneAPIToken" json:"openlaneAPIToken" jsonschema:"required description=the openlane api token"`

	DatabaseHost string `koanf:"databaseHost" json:"databaseHost" jsonschema:"required description=the database host"`
}

CustomDomainConfig contains the configuration for the custom domain workers

type DeleteCustomDomainArgs

type DeleteCustomDomainArgs struct {
	// ID of the custom domain in our system
	CustomDomainID             string `json:"custom_domain_id"`
	DNSVerificationID          string `json:"dns_verification_id"`
	CloudflareCustomHostnameID string `json:"cloudflare_custom_hostname_id"`
	CloudflareZoneID           string `json:"cloudflare_zone_id"`
}

DeleteCustomDomainArgs for the worker to process the custom domain

func (DeleteCustomDomainArgs) Kind

Kind satisfies the river.Job interface

type DeleteCustomDomainWorker

type DeleteCustomDomainWorker struct {
	river.WorkerDefaults[DeleteCustomDomainArgs]

	Config CustomDomainConfig
	// contains filtered or unexported fields
}

DeleteCustomDomainWorker delete the custom hostname from cloudflare and updates the records in our system

func (*DeleteCustomDomainWorker) WithCloudflareClient

WithCloudflareClient sets the Cloudflare client for the worker and returns the worker for method chaining

func (*DeleteCustomDomainWorker) WithOpenlaneClient

WithOpenlaneClient sets the Openlane client for the worker and returns the worker for method chaining

func (*DeleteCustomDomainWorker) Work

Work satisfies the river.Worker interface for the delete custom domain worker it deletes a custom domain for an organization

type DeleteExportContentArgs added in v0.22.3

type DeleteExportContentArgs struct {
}

DeleteExportContentArgs for the worker to process deletion of exports

func (DeleteExportContentArgs) Kind added in v0.22.3

Kind satisfies the river.Job interface

type DeleteExportContentWorker added in v0.22.3

type DeleteExportContentWorker struct {
	river.WorkerDefaults[DeleteExportContentArgs]

	Config DeleteExportWorkerConfig `koanf:"config" json:"config" jsonschema:"description=the configuration for deleting exports"`
	// contains filtered or unexported fields
}

DeleteExportContentWorker deletes exports that are older than the configured cutoff duration

func (*DeleteExportContentWorker) WithOpenlaneClient added in v0.22.3

WithOpenlaneClient sets the Openlane client for the worker and returns the worker for method chaining

func (*DeleteExportContentWorker) Work added in v0.22.3

Work satisfies the river.Worker interface for the delete export worker it deletes exports that are older than the configured cutoff duration

type DeleteExportWorkerConfig added in v0.22.3

type DeleteExportWorkerConfig struct {
	OpenlaneAPIHost  string `koanf:"openlaneAPIHost" json:"openlaneAPIHost" jsonschema:"required description=the openlane api host"`
	OpenlaneAPIToken string `koanf:"openlaneAPIToken" json:"openlaneAPIToken" jsonschema:"required description=the openlane api token"`

	// CutoffDuration defines the tolerance for exports. If you set 30 minutes, all exports older than 30 minutes
	// at the time of job execution will be deleted
	CutoffDuration time.Duration `` /* 152-byte string literal not displayed */
}

type ExportContentArgs added in v0.22.3

type ExportContentArgs struct {
	// ID of the export
	ExportID string `json:"export_id,omitempty"`
	// UserID of the user who requested the export (for system admin context)
	UserID string `json:"user_id,omitempty"`
	// OrganizationID of the organization context for the export
	OrganizationID string `json:"organization_id,omitempty"`
}

ExportContentArgs for the worker to process and update the record for the updated content

func (ExportContentArgs) Kind added in v0.22.3

func (ExportContentArgs) Kind() string

Kind satisfies the river.Job interface

type ExportContentWorker added in v0.22.3

type ExportContentWorker struct {
	river.WorkerDefaults[ExportContentArgs]

	Config ExportWorkerConfig `koanf:"config" json:"config" jsonschema:"description=the configuration for exporting"`
	// contains filtered or unexported fields
}

ExportContentWorker exports the content into csv and makes it downloadable

func (*ExportContentWorker) WithOpenlaneClient added in v0.22.3

WithOpenlaneClient sets the Openlane client for the worker and returns the worker for method chaining

func (*ExportContentWorker) WithRequester added in v0.24.1

func (w *ExportContentWorker) WithRequester(requester *httpsling.Requester) *ExportContentWorker

WithRequester sets the httpsling requester to use for HTTP requests

func (*ExportContentWorker) Work added in v0.22.3

Work satisfies the river.Worker interface for the export content worker it creates a csv, uploads it and associates it with the export

type ExportWorkerConfig added in v0.22.3

type ExportWorkerConfig struct {
	OpenlaneAPIHost  string `koanf:"openlaneAPIHost" json:"openlaneAPIHost" jsonschema:"required description=the openlane api host"`
	OpenlaneAPIToken string `koanf:"openlaneAPIToken" json:"openlaneAPIToken" jsonschema:"required description=the openlane api token"`
}

type MissingRequiredArgError

type MissingRequiredArgError struct {
	// Arg is the required argument that was not provided
	Arg string `json:"arg"`
	// Job is the job that requires the argument
	Job string `json:"job"`
}

MissingRequiredArgError is returned when a required argument was not provided to a job

func (*MissingRequiredArgError) Error

func (e *MissingRequiredArgError) Error() string

Error returns the MissingRequiredArgError in string format

type ValidateCustomDomainArgs

type ValidateCustomDomainArgs struct {
	CustomDomainID string `json:"custom_domain_id"`
}

ValidateCustomDomainArgs for the worker to process the custom domain

func (ValidateCustomDomainArgs) Kind

Kind satisfies the river.Job interface

type ValidateCustomDomainWorker

type ValidateCustomDomainWorker struct {
	river.WorkerDefaults[ValidateCustomDomainArgs]

	Config CustomDomainConfig
	// contains filtered or unexported fields
}

ValidateCustomDomainWorker checks cloudflare custom domain(s), and updates the status in our system

func (*ValidateCustomDomainWorker) WithCloudflareClient

func (*ValidateCustomDomainWorker) WithOpenlaneClient

func (*ValidateCustomDomainWorker) Work

ValidateCustomDomainConfig contains the configuration for the worker Work satisfies the river.Worker interface for the validate custom domain worker. It validates custom domains by checking their status in Cloudflare and updating our system with the current verification status.

Jump to

Keyboard shortcuts

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