cronjoborg

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 8 Imported by: 0

README

cron-job.org

Wrapper around the https://cron-job.org REST API.

Get your API key there and start using the API right away.

Usage

go get -u "github.com/Karitham/gocronjob"

See the examples.

Documentation

Index

Constants

View Source
const (
	// Unknown / not executed yet
	JobStatusUnknown = iota

	// OK
	JobStatusOK

	// Failed (DNS error)
	JobStatusFailedDNS

	// Failed (could not connect to host)
	JobStatusFailedCouldNotConnect

	// Failed (HTTP error)
	JobStatusFailedHTTPError

	// Failed (timeout)
	JobStatusFailedTimeout

	// Failed (too much response data)
	JobStatusFailedTooMuchResponse

	// Failed (invalid URL)
	JobStatusFailedInvalidURL

	// Failed (internal errors)
	JobStatusFailedInternalError

	// Failed (unknown reason)
	JobStatusFailedUknown
)
View Source
const (
	// Default job
	JobTypeDefault = iota

	// Monitoring job (used in a status monitor)
	JobTypeMonitoring
)
View Source
const (
	RequestMethodGet = iota
	RequestMethodPost
	RequestMethodOptions
	RequestMethodHead
	RequestMethodPut
	RequestMethodDelete
	RequestMethodTrace
	RequestMethodConnect
	RequestMethodPatch
)
View Source
const APIURL = "https://api.cron-job.org"

Variables

This section is empty.

Functions

func WithClient

func WithClient(httpc *http.Client) func(*Client)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a cron-job.org client

func New

func New(APIKey string, opts ...func(*Client)) *Client

func (*Client) DeleteJob

func (c *Client) DeleteJob(id int) error

DeleteJob https://docs.cron-job.org/rest-api.html#deleting-a-cron-job

func (*Client) GetHistoryDetails

func (c *Client) GetHistoryDetails(jobID int, historyID int) (HistoryItem, error)

GetHistoryDetails https://docs.cron-job.org/rest-api.html#retrieving-job-execution-history-item-details

func (*Client) ListJobs

func (c *Client) ListJobs() ([]Job, error)

ListJobs https://docs.cron-job.org/rest-api.html#listing-cron-jobs

func (*Client) NewRequest

func (c *Client) NewRequest(method string, body io.Reader, pathParts ...interface{}) (*http.Request, error)

type DetailedJob

type DetailedJob struct {
	Job
	// HTTP authentication settings
	Auth JobAuth `json:"auth"`

	// Notification settings
	Notification JobNotificationSettings `json:"notification"`

	// Extended request data
	ExtendedData JobExtendedData `json:"extendedData"`
}

DetailedJob https://docs.cron-job.org/rest-api.html#jobauth

type HistoryItem

type HistoryItem struct {
	// Identifier of the associated cron job
	JobID int `json:"jobId"`

	// Identifier of the history item
	Identifier string `json:"identifier"`

	// Unix timestamp (in seconds) of the actual execution
	Date Seconds `json:"date"`

	// Unix timestamp (in seconds) of the planned/ideal execution
	DatePlanned Seconds `json:"datePlanned"`

	// Scheduling jitter in milliseconds
	Jitter Milliseconds `json:"jitter"`

	// Job URL at time of execution
	URL string `json:"url"`

	// Actual job duration in milliseconds
	Duration Milliseconds `json:"duration"`

	// Status of execution
	Status JobStatus `json:"status"`

	// Detailed job status Description
	StatusText string `json:"statusText"`

	// HTTP status code returned by the host, if any
	HTTPStatus int `json:"httpStatus"`

	// Raw response headers returned by the host (null if unavailable)
	Headers string `json:"headers,omitempty"`

	// Raw response body returned by the host (null if unavailable)
	Body string `json:"body"`

	// Additional timing information for this request
	Stats HistoryItemStats `json:"stats"`
}

HistoryItem https://docs.cron-job.org/rest-api.html#historyitem

type HistoryItemStats

type HistoryItemStats struct {
	// Time from transfer start until name lookups completed (in microseconds)
	NameLookup Microseconds `json:"nameLookup"`

	// Time from transfer start until socket connect completed (in microseconds)
	Connect Microseconds `json:"connect"`

	// Time from transfer start until SSL handshake completed (n microseconds) - 0 if not using SSL
	AppConnect Microseconds `json:"appConnect"`

	// Time from transfer start until beginning of data transfer (in microseconds)
	PreTransfer Microseconds `json:"preTransfer"`

	// Time from transfer start until the first response byte is received (in microseconds)
	StartTransfer Microseconds `json:"startTransfer"`

	// Total transfer time (in microseconds)
	Total Microseconds `json:"total"`
}

HistoryItemStats https://docs.cron-job.org/rest-api.html#historyitemstats

type Job

type Job struct {
	// Job identifier
	JobID int `json:"jobId"`

	// Whether the job is enabled (i.e. being executed) or not
	Enabled bool `json:"enabled"`

	// Job title
	Title string `json:"title"`

	// Whether to save job response header/body or not
	SaveResponses bool `json:"saveResponses"`

	// Job URL
	URL string `json:"url"`

	// Last execution status
	LastStatus JobStatus `json:"lastStatus"`

	// Last execution duration in milliseconds
	LastDuration Milliseconds `json:"lastDuration"`

	// Unix timestamp of last execution (in seconds)
	LastExecution Seconds `json:"lastExecution"`

	// Unix timestamp of predicted next execution (in seconds), null if no prediction available
	NextExecution Seconds `json:"nextExecution"`

	// Job type
	Type JobType `json:"type"`

	// Job timeout in seconds
	RequestTimeout Seconds `json:"requestTimeout"`

	// Job schedule
	Schedule Schedule `json:"schedule"`

	// HTTP request method
	RequestMethod RequestMethod `json:"requestMethod"`
}

Job https://docs.cron-job.org/rest-api.html#job

type JobAuth

type JobAuth struct {
	// Whether to enable HTTP basic authentication or not.
	Enable bool `json:"enable"`

	// HTTP basic auth username
	User string `json:"user"`

	// HTTP basic auth password
	Password string `json:"password"`
}

JobAuth https://docs.cron-job.org/rest-api.html#jobauth

type JobExtendedData

type JobExtendedData struct {
	// Request headers (key-value dictionary)
	Headers map[string]string `json:"headers"`

	// Request body data
	Body string `json:"body"`
}

JobExtendedData https://docs.cron-job.org/rest-api.html#jobextendeddata

type JobHistory

type JobHistory struct {
	History     HistoryItem `json:"history"`
	Predictions []Seconds   `json:"predictions"`
}

JobHistory is a cron-job.org job history

type JobNotificationSettings

type JobNotificationSettings struct {
	// Whether to send a notification on job failure or not.
	OnFailure bool `json:"onFailure"`

	// Whether to send a notification when the job succeeds after a prior failure or not.
	OnSuccess bool `json:"onSuccess"`

	// Whether to send a notification when the job has been disabled automatically or not.
	OnDisable bool `json:"onDisable"`
}

JobNotificationSettings https://docs.cron-job.org/rest-api.html#job

type Microseconds

type Microseconds int64

Microseconds represents a time.Time in microseconds

func (Microseconds) Time

func (m Microseconds) Time() time.Time

Time returns a time.Time from the Microseconds

type Milliseconds

type Milliseconds int64

Milliseconds represents a time.Time in milliseconds

func (Milliseconds) Time

func (m Milliseconds) Time() time.Time

type Schedule

type Schedule struct {
	// Schedule time zone (see here for a list of supported values)
	Timezone string `json:"timezone"`

	// Hours in which to execute the job (0-23; [-1] = every hour)
	Hours []int `json:"hours"`

	// Days of month in which to execute the job (1-31; [-1] = every day of month)
	Mdays []int `json:"mdays"`

	// Minutes in which to execute the job (0-59; [-1] = every minute)
	Minutes []int `json:"minutes"`

	// Months in which to execute the job (1-12; [-1] = every month)
	Month []int `json:"months"`

	// Days of week in which to execute the job (0-6; [-1] = every day of week)
	WDays []int `json:"wdays"`
}

Schedule https://docs.cron-job.org/rest-api.html#jobschedule

func (Schedule) MarshalJSON

func (s Schedule) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

type Seconds

type Seconds int64

Seconds represents a time.Time in seconds

func (Seconds) Time

func (s Seconds) Time() time.Time

Time returns a time.Time from the Seconds

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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