Documentation
¶
Overview ¶
Package mailmantasks provides the official Go client for Mailman's hosted Tasks API, using only the standard library.
Create a Client with New and an API key from Mailman → Settings → Tasks API. Mailman must be open and connected on the user's computer.
Run creates a task and waits for its result. Concurrent waits share a poller per group. Poll is a destructive low-level read: results leave the server once returned. Waiter cancellation never aborts a poll already in flight; Close cancels all requests and may discard responses in flight.
Task times are seconds. The default task timeout is 300 seconds, with a maximum of 3600. Every HTTP request has a 15-second total timeout.
See https://getmailman.app/developers and https://getmailman.app/tasks-api.md.
Index ¶
- Constants
- Variables
- type AuthError
- type Client
- func (c *Client) Close()
- func (c *Client) CreateTask(ctx context.Context, t MailTask) (string, error)
- func (c *Client) Poll(ctx context.Context, group string) ([]TaskResult, error)
- func (c *Client) Run(ctx context.Context, t MailTask) (TaskResult, error)
- func (c *Client) Verify(ctx context.Context) error
- func (c *Client) Wait(ctx context.Context, id string, opts ...WaitOption) (TaskResult, error)
- type InvalidRequestError
- type MailElement
- type MailFilter
- type MailTask
- type MailmanError
- type NetworkError
- type Option
- type PayloadTooLargeError
- type PendingLimitError
- type RateLimitError
- type RequestTimeoutError
- type ServerBusyError
- type TaskFailedError
- type TaskResult
- type TaskTimeoutError
- type TooManyTasksError
- type WaitOption
Constants ¶
const ( TargetFrom = "from" TargetSubject = "subject" TargetBody = "body" ComparatorIncludes = "includes" ComparatorExcludes = "excludes" ComparatorMatches = "matches" ComparatorFindByRegex = "findByRegex" FormatterText = "text" FormatterHTML = "html" FormatterLink = "link" FormatterNumeric = "numeric" RegexSourcePretty = "pretty" RegexSourceRaw = "raw" StatusPending = "pending" StatusSuccess = "success" StatusError = "error" StatusTimeout = "timeout" )
const Version = "0.2.0"
Variables ¶
var ErrClosed = errors.New("mailman tasks client is closed")
Functions ¶
This section is empty.
Types ¶
type AuthError ¶
type AuthError struct{ *MailmanError }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Close ¶
func (c *Client) Close()
Close cancels all requests, joins pollers, and wakes waiters. Results in flight may be discarded. It is safe to call more than once.
func (*Client) CreateTask ¶
func (*Client) Poll ¶
Poll performs exactly one destructive request. Store every returned result. The caller context bounds admission only. Once admitted, the HTTP request finishes under its own 15-second timeout, unless Close cancels the client. Do not combine Poll with another consumer of the same group.
func (*Client) Wait ¶
func (c *Client) Wait(ctx context.Context, id string, opts ...WaitOption) (TaskResult, error)
type InvalidRequestError ¶
type InvalidRequestError struct{ *MailmanError }
func (*InvalidRequestError) Unwrap ¶
func (e *InvalidRequestError) Unwrap() error
type MailElement ¶
type MailElement struct {
Name string `json:"name"`
Target string `json:"target"`
Selector string `json:"selector,omitempty"`
Regex string `json:"regex,omitempty"`
RegexSource string `json:"regexSource,omitempty"`
Formatter string `json:"formatter,omitempty"`
Penetrate bool `json:"penetrate,omitempty"`
}
type MailFilter ¶
type MailTask ¶
type MailTask struct {
Email string `json:"email"`
ReceivedAt int64 `json:"receivedAt"`
Timeout uint32 `json:"timeout"`
Group string `json:"group"`
TemplateID string `json:"templateId,omitempty"`
MailFilters []MailFilter `json:"mailFilters"`
MailElements []MailElement `json:"mailElements"`
}
MailTask uses seconds for ReceivedAt (Unix time) and Timeout. Zero values select client defaults; timeouts above 3600 are clamped.
type MailmanError ¶
MailmanError describes an HTTP error. RetryAfter is zero when absent.
func (*MailmanError) Error ¶
func (e *MailmanError) Error() string
type NetworkError ¶
NetworkError is a transport or response-read failure. Error omits the cause text to keep credentials out of messages; Unwrap preserves cause inspection. MayHaveBeenAccepted is conservatively true for every failed create request: do not automatically retry it, as the task may already exist.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type Option ¶
type Option func(*Client)
func WithBaseURL ¶
func WithHTTPClient ¶
func WithUserAgent ¶
type PayloadTooLargeError ¶
type PayloadTooLargeError struct{ *MailmanError }
func (*PayloadTooLargeError) Unwrap ¶
func (e *PayloadTooLargeError) Unwrap() error
type PendingLimitError ¶
type PendingLimitError struct{ *MailmanError }
func (*PendingLimitError) Unwrap ¶
func (e *PendingLimitError) Unwrap() error
type RateLimitError ¶
type RateLimitError struct{ *MailmanError }
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type RequestTimeoutError ¶
type RequestTimeoutError struct{ *MailmanError }
func (*RequestTimeoutError) Unwrap ¶
func (e *RequestTimeoutError) Unwrap() error
type ServerBusyError ¶
type ServerBusyError struct{ *MailmanError }
func (*ServerBusyError) Unwrap ¶
func (e *ServerBusyError) Unwrap() error
type TaskFailedError ¶
type TaskFailedError struct{ ID, ErrorStatus, ErrorMessage string }
func (*TaskFailedError) Error ¶
func (e *TaskFailedError) Error() string
type TaskResult ¶
type TaskTimeoutError ¶
type TaskTimeoutError struct{ ID, Reason string }
TaskTimeoutError distinguishes a completed timeout from a lost result deadline. Reason is "timeout" when no matching email arrived, or "deadline" when no result arrived.
func (*TaskTimeoutError) Error ¶
func (e *TaskTimeoutError) Error() string
type TooManyTasksError ¶
type TooManyTasksError struct{ Limit int }
TooManyTasksError means client tracking capacity was reached. No create request was sent. Slots become available when tracked tasks safely expire.
func (*TooManyTasksError) Error ¶
func (e *TooManyTasksError) Error() string
type WaitOption ¶
type WaitOption func(*waitOptions)
func WithDeadline ¶
func WithDeadline(deadline time.Time) WaitOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) WaitOption
WithTimeout bounds a wait from the moment the option is constructed.
func WithWaitGroup ¶
func WithWaitGroup(group string) WaitOption