worker

package
v0.0.0-...-65ffb28 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Embedded GOGS API client
	*gogs.Client
	// GIN client for running git and git-annex operations. Also implements
	// some of the GOGS client functionality.
	GIN *ginclient.Client
	// contains filtered or unexported fields
}

Client embeds gogs.Client to extend functionality with new convenience methods. (New clients may be added in the future using the same interface).

func NewClient

func NewClient(webURL, gitURL, token string) *Client

NewClient returns a new worker Client.

func (*Client) CloneRepo

func (client *Client) CloneRepo(repo, destdir string) error

CloneRepo clones repository 'repo' into directory 'destdir'. The repository should be in the form user/repository, without any server information. The server address is configured in the client.

func (*Client) InitGINClient

func (client *Client) InitGINClient() error

InitGINClient logs in to the GIN server, sets up the local configuration, and returns a new ginclient.Client instance for running git and git-annex commands.

type PostAction

type PostAction func(v map[string][]string, botClient, userClient *Client) ([]string, error)

PostAction is a function that receives the form values when the form is submitted. It should perform actions for the user through the service given the form values and return a list of messages and/or an error if it fails.

type PreAction

type PreAction func(f form.Form, botClient, userClient *Client) (*form.Form, error)

PreAction is a function that receives the Form struct as defined for the service. It should return modified Form struct with values, constraints, or elements modified based on the permissions or actions supported for the bot and/or user, or any other external constraint that the function can evaluate.

type UserJob

type UserJob struct {
	*db.Job
	// contains filtered or unexported fields
}

UserJob extends db.Job with a user token to perform authenticated tasks on behalf of a given user.

func NewUserJob

func NewUserJob(client *Client, label string, values map[string][]string) *UserJob

NewUserJob returns a new UserJob initialised with the given custom function and user values.

type Worker

type Worker struct {

	// PreAction is used to prepare data to show the user, such as populating
	// form lists or showing information on static pages.
	PreAction PreAction
	// PostAction
	PostAction PostAction
	// contains filtered or unexported fields
}

Worker pool with queue for running Jobs asynchronously.

func New

func New(dbconn *db.Connection) *Worker

New returns a new Worker attached to the given database.

func (*Worker) Enqueue

func (w *Worker) Enqueue(j *UserJob)

Enqueue adds the job to the queue and stores it in the database.

func (*Worker) PreprocessForm

func (w *Worker) PreprocessForm(f *form.Form, userClient *Client) (*form.Form, error)

PreprocessForm runs the defined PreAction and returns a modified Form.

func (*Worker) SetClient

func (w *Worker) SetClient(c *Client)

SetClient assigns a service (bot) Client to the worker.

func (*Worker) SetLogger

func (w *Worker) SetLogger(l *log.Logger)

SetLogger sets the logger instance for the worker service. If unset the service defines its own logger with the same configuration as the standard Logger.

func (*Worker) Start

func (w *Worker) Start()

Start the worker queue, reading jobs sequentially from the channel and executing their custom function.

func (*Worker) Stop

func (w *Worker) Stop()

Stop sends the stop signal to the worker pool and closes the Job channel.

Jump to

Keyboard shortcuts

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