Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Providers []string `json:"providers"` Services []string `json:"services"` Source string `json:"source"` }
Config provides details on an event's task configuration. It is deprecated in v0.5 and should be removed in 0.8
type Error ¶
type Error struct { // Code string `json:"code"` TODO: future work Message string `json:"message"` }
Error captures an event's error information
type Event ¶
type Event struct { ID string `json:"id"` Success bool `json:"success"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` TaskName string `json:"task_name"` EventError *Error `json:"error"` // Config is deprecated in v0.5. This is configuration details about the // task rather than status information. Users should switch to using the // Get Task API to request the task's config information. // - Config should be removed in 0.8 Config *Config `json:"config"` }
Event captures the series of actions that needs to happen to update network infrastructure for a given task when it receives a service change from Consul. An event should encompass: rendering the task’s templates, creating/updating resources, and executing any handlers.
Example ¶
examples := []struct { name string taskName string expectErr bool }{ { "Event captures task erroring", "task_fail", true, }, { "Event captures task succeeding", "task_success", false, }, } for _, ex := range examples { fmt.Println("\nExample:", ex.name) _, _ = func() (string, error) { // setup capturing event event, err := NewEvent(ex.taskName, nil) if err != nil { fmt.Println(err) return "", err } // capture end result before returning function defer func() { event.End(err) fmt.Println("Task Name:", event.TaskName) fmt.Println("Success:", event.Success) fmt.Println("Error:", event.EventError) }() // function body ret, err := businessLogic(ex.expectErr) if err != nil { return "", err } return ret, nil }() }
Output: Example: Event captures task erroring Task Name: task_fail Success: false Error: &{error} Example: Event captures task succeeding Task Name: task_success Success: true Error: <nil>
func NewEvent ¶
NewEvent configures a new event with a task name and any relevant information that the task is configured with
func (*Event) End ¶
End sets the end time and captures any end results e.g. error, success status. Can only be called once