task_common

package
v0.0.0-...-ded851d Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: BSD-3-Clause Imports: 29 Imported by: 13

Documentation

Index

Constants

View Source
const (
	// Default page size used for pagination.
	DEFAULT_PAGE_SIZE = 10

	// Maximum page size used for pagination.
	MAX_PAGE_SIZE = 100

	CANCEL_SWARMING_TASKS_WORKER_POOL_SIZE = 100
)

Variables

View Source
var (

	// The location of the service account JSON file.
	ServiceAccountFile string

	// Will be used to construct task specific URLs in emails. Will have a trailing "/".
	WebappURL string
)

Functions

func AddAndTriggerTask

func AddAndTriggerTask(ctx context.Context, task AddTaskVars) error

AddAndTriggerTask adds the task to datastore and then triggers swarming tasks. The swarming tasks are triggered in a separate goroutine because if it is a GCE task then it can take a min or 2 to autoscale the GCE instances.

func AddHandlers

func AddHandlers(externalRouter chi.Router)

func AddTaskHandler

func AddTaskHandler(w http.ResponseWriter, r *http.Request, task AddTaskVars)

func DatastoreTaskQuery

func DatastoreTaskQuery(ctx context.Context, prototype Task, params QueryParams) *datastore.Iterator

func DeleteTaskHandler

func DeleteTaskHandler(prototype Task, w http.ResponseWriter, r *http.Request)

func EditTaskHandler

func EditTaskHandler(prototype Task, w http.ResponseWriter, r *http.Request)

func GetEmailRecipients

func GetEmailRecipients(runOwner string, ccList []string) []string

func GetFailureEmailRecipients

func GetFailureEmailRecipients(runOwner string, ccList []string) []string

Additionally adds CtAdmins to the email list.

func GetNextId

func GetNextId(ctx context.Context, kind ds.Kind, task Task) (int64, error)

func GetRunID

func GetRunID(task Task) string

Generates a unique ID for this task.

func GetTasksHandler

func GetTasksHandler(prototype Task, w http.ResponseWriter, r *http.Request)

func Init

func Init(ctx context.Context, local, enableAutoscaler bool, ctfeURL, serviceAccountFileFlagVal string, swarmingClient swarmingv2.SwarmingV2Client, cas cas.CAS, getGCETasksCount func(ctx context.Context) (int, error)) error

func RedoTaskHandler

func RedoTaskHandler(prototype Task, w http.ResponseWriter, r *http.Request)

func SetLogin

func SetLogin(p alogin.Login)

SetLogin should be called before any HTTP traffic is served.

func TriggerTaskOnSwarming

func TriggerTaskOnSwarming(ctx context.Context, task AddTaskVars, datastoreTask Task) error

func UpdateTaskSetCompleted

func UpdateTaskSetCompleted(ctx context.Context, task Task, success bool) error

UpdateTaskSetCompleted calls the task's SetCompleted method and updates it in Datastore.

func UpdateTaskSetStarted

func UpdateTaskSetStarted(ctx context.Context, runID, swarmingTaskID string, task Task) error

UpdateTaskSetStarted sets the following on the task and updates it in Datastore: * TsStarted * SwarmingTaskID * SwarmingLogsLink

Types

type AddTaskCommonVars

type AddTaskCommonVars struct {
	Username        string `json:"username"`
	TsAdded         string `json:"ts_added"`
	RepeatAfterDays string `json:"repeat_after_days"`
}

Data included in all tasks; set by AddTaskHandler.

func (*AddTaskCommonVars) GetAddTaskCommonVars

func (vars *AddTaskCommonVars) GetAddTaskCommonVars() *AddTaskCommonVars

func (*AddTaskCommonVars) IsAdminTask

func (vars *AddTaskCommonVars) IsAdminTask() bool

type AddTaskVars

type AddTaskVars interface {
	GetAddTaskCommonVars() *AddTaskCommonVars
	IsAdminTask() bool
	GetDatastoreKind() ds.Kind
	GetPopulatedDatastoreTask(ctx context.Context) (Task, error)
}

type BenchmarksPlatformsResponse

type BenchmarksPlatformsResponse struct {
	Benchmarks map[string]string `json:"benchmarks"`
	Platforms  map[string]string `json:"platforms"`
}

type ByPageSetDesc

type ByPageSetDesc []PageSet

ByPageSetDesc implements sort.Interface to order PageSets by their descriptions.

func (ByPageSetDesc) Len

func (p ByPageSetDesc) Len() int

func (ByPageSetDesc) Less

func (p ByPageSetDesc) Less(i, j int) bool

func (ByPageSetDesc) Swap

func (p ByPageSetDesc) Swap(i, j int)

type CLDataResponse

type CLDataResponse struct {
	CL            string `json:"cl"`
	Subject       string `json:"subject"`
	URL           string `json:"url"`
	Modified      string `json:"modified"`
	ChromiumPatch string `json:"chromium_patch"`
	SkiaPatch     string `json:"skia_patch"`
	V8Patch       string `json:"v8_patch"`
	CatapultPatch string `json:"catapult_patch"`
}

type ClusterTelemetryIDs

type ClusterTelemetryIDs struct {
	HighestID int64
}

type CommonCols

type CommonCols struct {
	DatastoreKey    *datastore.Key `json:"-" datastore:"__key__"`
	TsAdded         int64          `json:"ts_added"`
	TsStarted       int64          `json:"ts_started"`
	TsCompleted     int64          `json:"ts_completed"`
	Username        string         `json:"username"`
	Failure         bool           `json:"failure"`
	RepeatAfterDays int64          `json:"repeat_after_days"`
	SwarmingLogs    string         `json:"swarming_logs"`
	TaskDone        bool           `json:"task_done"`
	SwarmingTaskID  string         `json:"swarming_task_id"`

	Id         int    `json:"id" datastore:"-"`
	CanRedo    bool   `json:"can_redo" datastore:"-"`
	CanDelete  bool   `json:"can_delete" datastore:"-"`
	FutureDate bool   `json:"future_date" datastore:"-"`
	TaskType   string `json:"task_type" datastore:"-"`
	GetURL     string `json:"get_url" datastore:"-"`
	DeleteURL  string `json:"delete_url" datastore:"-"`
}

func (*CommonCols) GetCommonCols

func (dbrow *CommonCols) GetCommonCols() *CommonCols

type DeleteTaskRequest

type DeleteTaskRequest struct {
	Id int64 `json:"id"`
}

type EditTaskRequest

type EditTaskRequest struct {
	Id int64 `json:"id"`
}

type GetTasksResponse

type GetTasksResponse struct {
	Data        interface{}                   `json:"data"`
	Permissions []Permissions                 `json:"permissions"`
	Pagination  *httputils.ResponsePagination `json:"pagination"`
	IDs         []int64                       `json:"ids"`
}

type PageSet

type PageSet struct {
	Key         string `json:"key"`
	Description string `json:"description"`
}

type Permissions

type Permissions struct {
	DeleteAllowed bool
	RedoAllowed   bool
}

type QueryParams

type QueryParams struct {
	// If non-empty, limits to only tasks with the given username.
	Username string
	// Include only tasks that have completed successfully.
	SuccessfulOnly bool
	// Include only tasks that have completed after the specified timestamp.
	CompletedAfter int
	// Include only tasks that are not yet completed.
	PendingOnly bool
	// Include only completed tasks that are scheduled to repeat.
	FutureRunsOnly bool
	// Exclude tasks where page_sets is PAGESET_TYPE_DUMMY_1k.
	ExcludeDummyPageSets bool
	// If true, SELECT COUNT(*). If false, SELECT * and include ORDER BY and LIMIT clauses.
	CountQuery bool
	// First term of LIMIT clause; ignored if countQuery is true.
	Offset int
	// Second term of LIMIT clause; ignored if countQuery is true.
	Size int
}

type RedoTaskRequest

type RedoTaskRequest struct {
	Id int64 `json:"id"`
}

type Task

type Task interface {
	GetCommonCols() *CommonCols
	RunsOnGCEWorkers() bool
	TriggerSwarmingTaskAndMail(ctx context.Context, swarmingClient swarmingv2.SwarmingV2Client, casClient cas.CAS) error
	SendCompletionEmail(ctx context.Context, completedSuccessfully bool) error
	GetTaskName() string
	SetCompleted(success bool)
	GetDatastoreKind() ds.Kind
	GetDescription() string
	// Returns a slice of the struct type.
	Query(it *datastore.Iterator) (interface{}, error)
	// Returns the struct type.
	Get(c context.Context, key *datastore.Key) (Task, error)
	// Returns the corresponding AddTaskVars instance of this Task. The returned
	// instance is populated.
	GetPopulatedAddTaskVars() (AddTaskVars, error)
	// Returns the results link for this task if it completed successfully and if
	// the task supports results links.
	GetResultsLink() string
}

func AddTaskToDatastore

func AddTaskToDatastore(ctx context.Context, task AddTaskVars) (Task, error)

func AsTaskSlice

func AsTaskSlice(selectResult interface{}) []Task

Takes the result of Task.Query and returns a slice of Tasks containing the same objects.

type TaskPrioritiesResponse

type TaskPrioritiesResponse struct {
	TaskPriorities map[int]string `json:"task_priorities"`
}

Jump to

Keyboard shortcuts

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