Updated worker with correct api handling
This commit is contained in:
@@ -73,9 +73,14 @@ type WorkflowExecution struct {
|
|||||||
Locations []string `json:"locations"`
|
Locations []string `json:"locations"`
|
||||||
Workflow Workflow `json:"workflow"`
|
Workflow Workflow `json:"workflow"`
|
||||||
Results []ActionResult `json:"results"`
|
Results []ActionResult `json:"results"`
|
||||||
|
ExecutionVariables []struct {
|
||||||
|
Description string `json:"description" datastore:"description"`
|
||||||
|
ID string `json:"id" datastore:"id"`
|
||||||
|
Name string `json:"name" datastore:"name"`
|
||||||
|
Value string `json:"value" datastore:"value"`
|
||||||
|
} `json:"execution_variables,omitempty" datastore:"execution_variables,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Added environment for location to execute
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
AppName string `json:"app_name" datastore:"app_name"`
|
AppName string `json:"app_name" datastore:"app_name"`
|
||||||
AppVersion string `json:"app_version" datastore:"app_version"`
|
AppVersion string `json:"app_version" datastore:"app_version"`
|
||||||
@@ -84,10 +89,20 @@ type Action struct {
|
|||||||
ID string `json:"id" datastore:"id"`
|
ID string `json:"id" datastore:"id"`
|
||||||
IsValid bool `json:"is_valid" datastore:"is_valid"`
|
IsValid bool `json:"is_valid" datastore:"is_valid"`
|
||||||
IsStartNode bool `json:"isStartNode" datastore:"isStartNode"`
|
IsStartNode bool `json:"isStartNode" datastore:"isStartNode"`
|
||||||
|
Sharing bool `json:"sharing" datastore:"sharing"`
|
||||||
|
PrivateID string `json:"private_id" datastore:"private_id"`
|
||||||
Label string `json:"label" datastore:"label"`
|
Label string `json:"label" datastore:"label"`
|
||||||
|
SmallImage string `json:"small_image" datastore:"small_image,noindex" required:false yaml:"small_image"`
|
||||||
|
LargeImage string `json:"large_image" datastore:"large_image,noindex" yaml:"large_image" required:false`
|
||||||
Environment string `json:"environment" datastore:"environment"`
|
Environment string `json:"environment" datastore:"environment"`
|
||||||
Name string `json:"name" datastore:"name"`
|
Name string `json:"name" datastore:"name"`
|
||||||
Parameters []WorkflowAppActionParameter `json:"parameters" datastore: "parameters"`
|
Parameters []WorkflowAppActionParameter `json:"parameters" datastore: "parameters,noindex"`
|
||||||
|
ExecutionVariable struct {
|
||||||
|
Description string `json:"description" datastore:"description"`
|
||||||
|
ID string `json:"id" datastore:"id"`
|
||||||
|
Name string `json:"name" datastore:"name"`
|
||||||
|
Value string `json:"value" datastore:"value"`
|
||||||
|
} `json:"execution_variable,omitempty" datastore:"execution_variable,omitempty"`
|
||||||
Position struct {
|
Position struct {
|
||||||
X float64 `json:"x" datastore:"x"`
|
X float64 `json:"x" datastore:"x"`
|
||||||
Y float64 `json:"y" datastore:"y"`
|
Y float64 `json:"y" datastore:"y"`
|
||||||
@@ -132,10 +147,10 @@ type Trigger struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Workflow struct {
|
type Workflow struct {
|
||||||
Actions []Action `json:"actions" datastore:"actions"`
|
Actions []Action `json:"actions" datastore:"actions,noindex"`
|
||||||
Branches []Branch `json:"branches" datastore:"branches"`
|
Branches []Branch `json:"branches" datastore:"branches,noindex"`
|
||||||
Triggers []Trigger `json:"triggers" datastore:"triggers"`
|
Triggers []Trigger `json:"triggers" datastore:"triggers,noindex"`
|
||||||
Schedules []Schedule `json:"schedules" datastore:"schedules"`
|
Schedules []Schedule `json:"schedules" datastore:"schedules,noindex"`
|
||||||
Errors []string `json:"errors,omitempty" datastore:"errors"`
|
Errors []string `json:"errors,omitempty" datastore:"errors"`
|
||||||
Tags []string `json:"tags,omitempty" datastore:"tags"`
|
Tags []string `json:"tags,omitempty" datastore:"tags"`
|
||||||
ID string `json:"id" datastore:"id"`
|
ID string `json:"id" datastore:"id"`
|
||||||
@@ -153,6 +168,12 @@ type Workflow struct {
|
|||||||
Name string `json:"name" datastore:"name"`
|
Name string `json:"name" datastore:"name"`
|
||||||
Value string `json:"value" datastore:"value"`
|
Value string `json:"value" datastore:"value"`
|
||||||
} `json:"workflow_variables" datastore:"workflow_variables"`
|
} `json:"workflow_variables" datastore:"workflow_variables"`
|
||||||
|
ExecutionVariables []struct {
|
||||||
|
Description string `json:"description" datastore:"description"`
|
||||||
|
ID string `json:"id" datastore:"id"`
|
||||||
|
Name string `json:"name" datastore:"name"`
|
||||||
|
Value string `json:"value" datastore:"value"`
|
||||||
|
} `json:"execution_variables,omitempty" datastore:"execution_variables,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionResult struct {
|
type ActionResult struct {
|
||||||
@@ -196,22 +217,41 @@ type WorkflowAppActionParameter struct {
|
|||||||
} `json:"schema"`
|
} `json:"schema"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AuthenticationStore struct {
|
||||||
|
Key string `json:"key" datastore:"key"`
|
||||||
|
Value string `json:"value" datastore:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
type WorkflowAppAction struct {
|
type WorkflowAppAction struct {
|
||||||
|
Description string `json:"description" datastore:"description"`
|
||||||
|
ID string `json:"id" datastore:"id" yaml:"id,omitempty"`
|
||||||
|
Name string `json:"name" datastore:"name"`
|
||||||
|
Label string `json:"label" datastore:"label"`
|
||||||
|
NodeType string `json:"node_type" datastore:"node_type"`
|
||||||
|
Environment string `json:"environment" datastore:"environment"`
|
||||||
|
Sharing bool `json:"sharing" datastore:"sharing"`
|
||||||
|
PrivateID string `json:"private_id" datastore:"private_id"`
|
||||||
|
AppID string `json:"app_id" datastore:"app_id"`
|
||||||
|
Authentication []AuthenticationStore `json:"authentication" datastore:"authentication" yaml:"authentication,omitempty"`
|
||||||
|
Tested bool `json:"tested" datastore:"tested" yaml:"tested"`
|
||||||
|
Parameters []WorkflowAppActionParameter `json:"parameters" datastore: "parameters"`
|
||||||
|
ExecutionVariable struct {
|
||||||
Description string `json:"description" datastore:"description"`
|
Description string `json:"description" datastore:"description"`
|
||||||
ID string `json:"id" datastore:"id"`
|
ID string `json:"id" datastore:"id"`
|
||||||
Name string `json:"name" datastore:"name"`
|
Name string `json:"name" datastore:"name"`
|
||||||
NodeType string `json:"node_type" datastore:"node_type"`
|
Value string `json:"value" datastore:"value"`
|
||||||
Environment string `json:"environment" datastore:"environment"`
|
} `json:"execution_variable" datastore:"execution_variables"`
|
||||||
Parameters []WorkflowAppActionParameter `json:"parameters" datastore: "parameters"`
|
|
||||||
Returns struct {
|
Returns struct {
|
||||||
Description string `json:"description" datastore:"returns"`
|
Description string `json:"description" datastore:"returns" yaml:"description,omitempty"`
|
||||||
ID string `json:"id" datastore:"id"`
|
ID string `json:"id" datastore:"id" yaml:"id,omitempty"`
|
||||||
Schema struct {
|
Schema SchemaDefinition `json:"schema" datastore:"schema" yaml:"schema"`
|
||||||
Type string `json:"type" datastore:"type"`
|
|
||||||
} `json:"schema" datastore:"schema"`
|
|
||||||
} `json:"returns" datastore:"returns"`
|
} `json:"returns" datastore:"returns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SchemaDefinition struct {
|
||||||
|
Type string `json:"type" datastore:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
// removes every container except itself (worker)
|
// removes every container except itself (worker)
|
||||||
func shutdown(executionId, workflowId string) {
|
func shutdown(executionId, workflowId string) {
|
||||||
dockercli, err := dockerclient.NewEnvClient()
|
dockercli, err := dockerclient.NewEnvClient()
|
||||||
@@ -245,9 +285,6 @@ func shutdown(executionId, workflowId string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Add an API call to the backend
|
|
||||||
// fmt.Sprintf("AUTHORIZATION=%s", workflowExecution.Authorization),
|
|
||||||
|
|
||||||
fullUrl := fmt.Sprintf("%s/api/v1/workflows/%s/executions/%s/abort", baseUrl, workflowId, executionId)
|
fullUrl := fmt.Sprintf("%s/api/v1/workflows/%s/executions/%s/abort", baseUrl, workflowId, executionId)
|
||||||
req, err := http.NewRequest(
|
req, err := http.NewRequest(
|
||||||
"GET",
|
"GET",
|
||||||
@@ -259,6 +296,12 @@ func shutdown(executionId, workflowId string) {
|
|||||||
log.Println("Failed building request: %s", err)
|
log.Println("Failed building request: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Add an API call to the backend
|
||||||
|
authorization := os.Getenv("AUTHORIZATION")
|
||||||
|
if len(authorization) > 0 {
|
||||||
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", authorization))
|
||||||
|
}
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
//req.Header.Add("Authorization", authorization)
|
//req.Header.Add("Authorization", authorization)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
@@ -618,7 +661,7 @@ func handleExecution(client *http.Client, req *http.Request, workflowExecution W
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed deploying %s from image %s: %s", identifier, image, err)
|
log.Printf("Failed deploying %s from image %s: %s", identifier, image, err)
|
||||||
log.Printf("Should send status and exit the entire thing?")
|
log.Printf("Should send status and exit the entire thing?")
|
||||||
//shutdown(workflowExecution.ExecutionId)
|
shutdown(workflowExecution.ExecutionId, workflowExecution.Workflow.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
visited = append(visited, action.ID)
|
visited = append(visited, action.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user