crontriggers

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Overview

Package crontriggers provides interaction with the cron triggers API in the OpenStack Mistral service.

Cron trigger is an object that allows to run Mistral workflows according to a time pattern (Unix crontab patterns format). Once a trigger is created it will run a specified workflow according to its properties: pattern, first_execution_time and remaining_executions.

List cron triggers

To filter cron triggers from a list request, you can use advanced filters with special FilterType to check for equality, non equality, values greater or lower, etc. Default Filter checks equality, but you can override it with provided filter type.

listOpts := crontriggers.ListOpts{
	WorkflowName: &executions.ListFilter{
		Value: "Workflow1,Workflow2",
		Filter: executions.FilterIN,
	},
	CreatedAt: &executions.ListDateFilter{
		Value: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC),
		Filter: executions.FilterGTE,
	},
}

allPages, err := crontriggers.List(mistralClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allCrontriggers, err := crontriggers.ExtractCronTriggers(allPages)
if err != nil {
	panic(err)
}

for _, ct := range allCrontriggers {
	fmt.Printf("%+v\n", ct)
}

Create a cron trigger. This example will start the workflow "echo" each day at 8am, and it will end after 10 executions.

createOpts := &crontriggers.CreateOpts{
	Name:                "daily",
	Pattern:             "0 8 * * *",
	WorkflowName:        "echo",
	RemainingExecutions: 10,
	WorkflowParams: map[string]interface{}{
		"msg": "hello",
	},
	WorkflowInput: map[string]interface{}{
		"msg": "world",
	},
}
crontrigger, err := crontriggers.Create(mistralClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Get a cron trigger

crontrigger, err := crontriggers.Get(mistralClient, "0520ffd8-f7f1-4f2e-845b-55d953a1cf46").Extract()
if err != nil {
	panic(err)
}

fmt.Printf(%+v\n", crontrigger)

Delete a cron trigger

res := crontriggers.Delete(mistralClient, "0520ffd8-f7f1-4f2e-845b-55d953a1cf46")
if res.Err != nil {
	panic(res.Err)
}

Index

Constants

View Source
const (
	// FilterEQ checks equality.
	FilterEQ = "eq"
	// FilterNEQ checks non equality.
	FilterNEQ = "neq"
	// FilterIN checks for belonging in a list, comma separated.
	FilterIN = "in"
	// FilterNIN checks for values that does not belong from a list, comma separated.
	FilterNIN = "nin"
	// FilterGT checks for values strictly greater.
	FilterGT = "gt"
	// FilterGTE checks for values greater or equal.
	FilterGTE = "gte"
	// FilterLT checks for values strictly lower.
	FilterLT = "lt"
	// FilterLTE checks for values lower or equal.
	FilterLTE = "lte"
	// FilterHas checks for values that contains the requested parameter.
	FilterHas = "has"
)

Variables

This section is empty.

Functions

func List

List performs a call to list cron triggers. You may provide options to filter the results.

Types

type CreateOpts

type CreateOpts struct {
	// Name is the cron trigger name.
	Name string `json:"name"`

	// Pattern is a Unix crontab patterns format to execute the workflow.
	Pattern string `json:"pattern"`

	// RemainingExecutions sets the number of executions for the trigger.
	RemainingExecutions int `json:"remaining_executions,omitempty"`

	// WorkflowID is the unique id of the workflow.
	WorkflowID string `json:"workflow_id,omitempty" or:"WorkflowName"`

	// WorkflowName is the name of the workflow.
	// It is recommended to refer to workflow by the WorkflowID parameter instead of WorkflowName.
	WorkflowName string `json:"workflow_name,omitempty" or:"WorkflowID"`

	// WorkflowParams defines workflow type specific parameters.
	WorkflowParams map[string]interface{} `json:"workflow_params,omitempty"`

	// WorkflowInput defines workflow input values.
	WorkflowInput map[string]interface{} `json:"workflow_input,omitempty"`

	// FirstExecutionTime defines the first execution time of the trigger.
	FirstExecutionTime *time.Time `json:"-"`
}

CreateOpts specifies parameters used to create a cron trigger.

func (CreateOpts) ToCronTriggerCreateMap

func (opts CreateOpts) ToCronTriggerCreateMap() (map[string]interface{}, error)

ToCronTriggerCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToCronTriggerCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extension to add additional parameters to the Create request.

type CreateResult

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

CreateResult is the response of a Post operations. Call its Extract method to interpret it as a CronTrigger.

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new cron trigger.

func (CreateResult) Extract

func (r CreateResult) Extract() (*CronTrigger, error)

Extract helps to get a CronTrigger struct from a Get or a Create function.

type CronTrigger

type CronTrigger struct {
	// ID is the cron trigger's unique ID.
	ID string `json:"id"`

	// Name is the name of the cron trigger.
	Name string `json:"name"`

	// Pattern is the cron-like style pattern to execute the workflow.
	// Example of value: "* * * * *"
	Pattern string `json:"pattern"`

	// ProjectID is the project id owner of the cron trigger.
	ProjectID string `json:"project_id"`

	// RemainingExecutions is the number of remaining executions of this trigger.
	RemainingExecutions int `json:"remaining_executions"`

	// Scope is the scope of the trigger.
	// Values can be "private" or "public".
	Scope string `json:"scope"`

	// WorkflowID is the ID of the workflow linked to the trigger.
	WorkflowID string `json:"workflow_id"`

	// WorkflowName is the name of the workflow linked to the trigger.
	WorkflowName string `json:"workflow_name"`

	// WorkflowInput contains the workflow input values.
	WorkflowInput map[string]interface{} `json:"-"`

	// WorkflowParams contains workflow type specific parameters.
	WorkflowParams map[string]interface{} `json:"-"`

	// CreatedAt contains the cron trigger creation date.
	CreatedAt time.Time `json:"-"`

	// FirstExecutionTime is the date of the first execution of the trigger.
	FirstExecutionTime *time.Time `json:"-"`

	// NextExecutionTime is the date of the next execution of the trigger.
	NextExecutionTime *time.Time `json:"-"`
}

CronTrigger represents a workflow cron trigger on OpenStack mistral API.

func ExtractCronTriggers

func ExtractCronTriggers(r pagination.Page) ([]CronTrigger, error)

ExtractCronTriggers get the list of cron triggers from a page acquired from the List call.

func (*CronTrigger) UnmarshalJSON

func (r *CronTrigger) UnmarshalJSON(b []byte) error

UnmarshalJSON implements unmarshalling custom types

type CronTriggerPage

type CronTriggerPage struct {
	pagination.LinkedPageBase
}

CronTriggerPage contains a single page of all cron triggers from a List call.

func (CronTriggerPage) IsEmpty

func (r CronTriggerPage) IsEmpty() (bool, error)

IsEmpty checks if an CronTriggerPage contains any results.

func (CronTriggerPage) NextPageURL

func (r CronTriggerPage) NextPageURL() (string, error)

NextPageURL finds the next page URL in a page in order to navigate to the next page of results.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the result from a Delete operation. Call its ExtractErr method to determine the success of the call.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete deletes the specified cron trigger.

type FilterType

type FilterType string

FilterType represents a valid filter to use for filtering executions.

type GetResult

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

GetResult is the response of Get operations. Call its Extract method to interpret it as a CronTrigger.

func Get

func Get(client *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves details of a single cron trigger. Use Extract to convert its result into an CronTrigger.

func (GetResult) Extract

func (r GetResult) Extract() (*CronTrigger, error)

Extract helps to get a CronTrigger struct from a Get or a Create function.

type ListDateFilter

type ListDateFilter struct {
	Filter FilterType
	Value  time.Time
}

ListDateFilter allows to filter date parameters with different filters. Empty value for Filter checks for equality.

func (ListDateFilter) String

func (l ListDateFilter) String() string

type ListFilter

type ListFilter struct {
	Filter FilterType
	Value  string
}

ListFilter allows to filter string parameters with different filters. Empty value for Filter checks for equality.

func (ListFilter) String

func (l ListFilter) String() string

type ListIntFilter

type ListIntFilter struct {
	Filter FilterType
	Value  int
}

ListIntFilter allows to filter integer parameters with different filters. Empty value for Filter checks for equality.

func (ListIntFilter) String

func (l ListIntFilter) String() string

type ListOpts

type ListOpts struct {
	// WorkflowName allows to filter by workflow name.
	WorkflowName *ListFilter `q:"-"`
	// WorkflowID allows to filter by workflow id.
	WorkflowID string `q:"workflow_id"`
	// WorkflowInput allows to filter by specific workflow inputs.
	WorkflowInput map[string]interface{} `q:"-"`
	// WorkflowParams allows to filter by specific workflow parameters.
	WorkflowParams map[string]interface{} `q:"-"`
	// Scope filters by the trigger's scope.
	// Values can be "private" or "public".
	Scope string `q:"scope"`
	// Name allows to filter by trigger name.
	Name *ListFilter `q:"-"`
	// Pattern allows to filter by pattern.
	Pattern *ListFilter `q:"-"`
	// RemainingExecutions allows to filter by remaining executions.
	RemainingExecutions *ListIntFilter `q:"-"`
	// FirstExecutionTime allows to filter by first execution time.
	FirstExecutionTime *ListDateFilter `q:"-"`
	// NextExecutionTime allows to filter by next execution time.
	NextExecutionTime *ListDateFilter `q:"-"`
	// CreatedAt allows to filter by trigger creation date.
	CreatedAt *ListDateFilter `q:"-"`
	// UpdatedAt allows to filter by trigger last update date.
	UpdatedAt *ListDateFilter `q:"-"`
	// ProjectID allows to filter by given project id. Admin required.
	ProjectID string `q:"project_id"`
	// AllProjects requests to get executions of all projects. Admin required.
	AllProjects int `q:"all_projects"`
	// SortDirs allows to select sort direction.
	// It can be "asc" or "desc" (default).
	SortDirs string `q:"sort_dirs"`
	// SortKeys allows to sort by one of the cron trigger attributes.
	SortKeys string `q:"sort_keys"`
	// Marker and Limit control paging.
	// Marker instructs List where to start listing from.
	Marker string `q:"marker"`
	// Limit instructs List to refrain from sending excessively large lists of
	// cron triggers.
	Limit int `q:"limit"`
}

ListOpts filters the result returned by the List() function.

func (ListOpts) ToCronTriggerListQuery

func (opts ListOpts) ToCronTriggerListQuery() (string, error)

ToCronTriggerListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToCronTriggerListQuery() (string, error)
}

ListOptsBuilder allows extension to add additional parameters to the List request.

Jump to

Keyboard shortcuts

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