worker

package
v0.0.0-...-56e218b Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

IronWorker (elastic computing) client library

Index

Constants

This section is empty.

Variables

View Source
var (
	TaskDir string

	TaskId string
)
View Source
var GoCodeRunner = []byte(`#!/bin/sh
root() {
  while [ $# -gt 0 ]; do
    if [ "$1" = "-d" ]; then
      printf "%s\n" "$2"
      break
    fi
  done
}
cd "$(root "$@")"
chmod +x worker
./worker "$@"
`)

Functions

func ConfigAsString

func ConfigAsString() (string, error)

func ConfigFromJSON

func ConfigFromJSON(v interface{}) error

func ConfigReader

func ConfigReader() (io.ReadCloser, error)

func IronTaskDir

func IronTaskDir() string

func IronTaskId

func IronTaskId() string

func ParseFlags

func ParseFlags()

call this to parse flags before using the other methods.

func PayloadAsString

func PayloadAsString() (string, error)

func PayloadFromJSON

func PayloadFromJSON(v interface{}) error

func PayloadReader

func PayloadReader() (io.ReadCloser, error)

Types

type Code

type Code struct {
	Id             string        `json:"id,omitempty"`
	Name           string        `json:"name"`
	Runtime        string        `json:"runtime,omitempty"`
	FileName       string        `json:"file_name,omitempty"`
	Config         string        `json:"config,omitempty"`
	MaxConcurrency int           `json:"max_concurrency,omitempty"`
	Retries        int           `json:"retries,omitempty"`
	Stack          string        `json:"stack,omitempty"`
	Image          string        `json:"image,omitempty"`
	Command        string        `json:"command,omitempty"`
	RetriesDelay   time.Duration `json:"-"`
	Source         CodeSource    `json:"-"`
	Host           string        `json:"host,omitempty"`
}

type CodeInfo

type CodeInfo struct {
	Id              string    `json:"id"`
	LatestChecksum  string    `json:"latest_checksum,omitempty"`
	LatestHistoryId string    `json:"latest_history_id"`
	Name            string    `json:"name"`
	ProjectId       string    `json:"project_id"`
	Runtime         *string   `json:"runtime,omitempty"`
	Rev             int       `json:"rev"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
	LatestChange    time.Time `json:"latest_change"`
}

type CodeSource

type CodeSource map[string][]byte // map[pathInZip]code

type Schedule

type Schedule struct {
	CodeName       string         `json:"code_name"`
	Delay          *time.Duration `json:"delay"`
	EndAt          *time.Time     `json:"end_at"`
	MaxConcurrency *int           `json:"max_concurrency"`
	Name           string         `json:"name"`
	Payload        string         `json:"payload"`
	Priority       *int           `json:"priority"`
	RunEvery       *int           `json:"run_every"`
	RunTimes       *int           `json:"run_times"`
	StartAt        *time.Time     `json:"start_at"`
	Cluster        string         `json:"cluster"`
	Label          string         `json:"label"`
}

type ScheduleInfo

type ScheduleInfo struct {
	CodeName       string    `json:"code_name"`
	CreatedAt      time.Time `json:"created_at"`
	EndAt          time.Time `json:"end_at"`
	Id             string    `json:"id"`
	LastRunTime    time.Time `json:"last_run_time"`
	MaxConcurrency int       `json:"max_concurrency"`
	Msg            string    `json:"msg"`
	NextStart      time.Time `json:"next_start"`
	ProjectId      string    `json:"project_id"`
	RunCount       int       `json:"run_count"`
	RunTimes       int       `json:"run_times"`
	StartAt        time.Time `json:"start_at"`
	Status         string    `json:"status"`
	UpdatedAt      time.Time `json:"updated_at"`
}

type Task

type Task struct {
	CodeName string         `json:"code_name"`
	Payload  string         `json:"payload"`
	Priority int            `json:"priority"`
	Timeout  *time.Duration `json:"timeout"`
	Delay    *time.Duration `json:"delay"`
	Cluster  string         `json:"cluster"`
	Label    string         `json:"label"`
}

type TaskInfo

type TaskInfo struct {
	CodeHistoryId string    `json:"code_history_id"`
	CodeId        string    `json:"code_id"`
	CodeName      string    `json:"code_name"`
	CodeRev       string    `json:"code_rev"`
	Id            string    `json:"id"`
	Payload       string    `json:"payload"`
	ProjectId     string    `json:"project_id"`
	Status        string    `json:"status"`
	Msg           string    `json:"msg,omitempty"`
	ScheduleId    string    `json:"schedule_id"`
	Duration      int       `json:"duration"`
	RunTimes      int       `json:"run_times"`
	Timeout       int       `json:"timeout"`
	Percent       int       `json:"percent,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	StartTime     time.Time `json:"start_time"`
	EndTime       time.Time `json:"end_time"`
}

type TaskListParams

type TaskListParams struct {
	CodeName string
	Label    string
	Page     int
	PerPage  int
	FromTime time.Time
	ToTime   time.Time
	Statuses []string
}

type Worker

type Worker struct {
	Settings config.Settings
}

func New

func New() *Worker

func (*Worker) CodePackageDelete

func (w *Worker) CodePackageDelete(codeId string) (err error)

CodePackageDelete deletes a code package

func (*Worker) CodePackageDownload

func (w *Worker) CodePackageDownload(codeId string) (code Code, err error)

CodePackageDownload downloads a code package

func (*Worker) CodePackageInfo

func (w *Worker) CodePackageInfo(codeId string) (code CodeInfo, err error)

CodePackageInfo gets info about a code package

func (*Worker) CodePackageList

func (w *Worker) CodePackageList(page, perPage int) (codes []CodeInfo, err error)

CodePackageList lists code packages.

The page argument decides the page of code packages you want to retrieve, starting from 0, maximum is 100.

The perPage argument determines the number of code packages to return. Note this is a maximum value, so there may be fewer packages returned if there aren’t enough results. If this is < 1, 1 will be the default. Maximum is 100.

func (*Worker) CodePackageRevisions

func (w *Worker) CodePackageRevisions(codeId string) (code Code, err error)

CodePackageRevisions lists the revisions of a code pacakge

func (*Worker) CodePackageUpload

func (w *Worker) CodePackageUpload(code Code) (id string, err error)

CodePackageUpload uploads a code package

func (*Worker) FilteredTaskList

func (w *Worker) FilteredTaskList(params TaskListParams) (tasks []TaskInfo, err error)

func (*Worker) Schedule

func (w *Worker) Schedule(schedules ...Schedule) (scheduleIds []string, err error)

Schedule a Task

func (*Worker) ScheduleCancel

func (w *Worker) ScheduleCancel(scheduleId string) (err error)

ScheduleCancel cancels a scheduled task

func (*Worker) ScheduleInfo

func (w *Worker) ScheduleInfo(scheduleId string) (info ScheduleInfo, err error)

ScheduleInfo gets info about a scheduled task

func (*Worker) ScheduleList

func (w *Worker) ScheduleList() (schedules []ScheduleInfo, err error)

ScheduleList lists Scheduled Tasks

func (*Worker) TaskCancel

func (w *Worker) TaskCancel(taskId string) (err error)

TaskCancel cancels a Task

func (*Worker) TaskInfo

func (w *Worker) TaskInfo(taskId string) (task TaskInfo, err error)

TaskInfo gives info about a given task

func (*Worker) TaskList

func (w *Worker) TaskList() (tasks []TaskInfo, err error)

func (*Worker) TaskLog

func (w *Worker) TaskLog(taskId string) (log []byte, err error)

func (*Worker) TaskProgress

func (w *Worker) TaskProgress(taskId string, progress int, msg string) (err error)

TaskProgress sets a Task's Progress

func (*Worker) TaskQueue

func (w *Worker) TaskQueue(tasks ...Task) (taskIds []string, err error)

TaskQueue queues a task

func (*Worker) TaskQueueWebhook

func (w *Worker) TaskQueueWebhook() (err error)

TaskQueueWebhook queues a Task from a Webhook

func (*Worker) WaitForTask

func (w *Worker) WaitForTask(taskId string) chan TaskInfo

WaitForTask returns a channel that will receive the completed task and is closed afterwards. If an error occured during the wait, the channel will be closed.

func (*Worker) WaitForTaskLog

func (w *Worker) WaitForTaskLog(taskId string) chan []byte

Jump to

Keyboard shortcuts

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