diff --git a/cmd/actionExecute.go b/cmd/actionExecute.go index 4a80139..7c4e079 100644 --- a/cmd/actionExecute.go +++ b/cmd/actionExecute.go @@ -90,7 +90,7 @@ func actionExecute() { log.Fatalf("error: failed to get action: %v", err) } - newItem, err := core.ExecuteItemAction(item, actionExecuteSource, argv, time.Minute) + newItem, err := core.ExecuteItemAction(item, actionExecuteSource, argv, nil, "", time.Minute) if err != nil { log.Fatalf("error executing action: %v", err) } diff --git a/cmd/sourceFetch.go b/cmd/sourceFetch.go index 8981d09..a24cd6c 100644 --- a/cmd/sourceFetch.go +++ b/cmd/sourceFetch.go @@ -51,7 +51,7 @@ func sourceFetch() { log.Fatalf("error: failed to get fetch action: %v", err) } - items, err := core.Execute(sourceFetchSource, argv, nil, "", time.Minute) + items, err := core.Execute(sourceFetchSource, argv, nil, "", "", time.Minute) if err != nil { log.Fatalf("error: failed to execute fetch: %v", err) } diff --git a/cmd/sourceTest.go b/cmd/sourceTest.go index f68d334..f248ab8 100644 --- a/cmd/sourceTest.go +++ b/cmd/sourceTest.go @@ -38,7 +38,7 @@ func init() { func sourceTest(cmd []string) { formatter := formatAs(sourceTestFormat) - items, err := core.Execute("", cmd, sourceTestEnv, "", time.Minute) + items, err := core.Execute("", cmd, sourceTestEnv, "", "", time.Minute) log.Printf("Returned %d items", len(items)) if err != nil { log.Fatal(err) diff --git a/core/action.go b/core/action.go index b10151e..14238a7 100644 --- a/core/action.go +++ b/core/action.go @@ -127,10 +127,11 @@ func Execute( source string, argv []string, env []string, + statePath string, input string, timeout time.Duration, ) ([]Item, error) { - log.Printf("Executing %v", argv) + log.Printf("executing %v", argv) if len(argv) == 0 { return nil, errors.New("empty argv") @@ -139,7 +140,7 @@ func Execute( return nil, errors.New("empty source") } - env = append(env, "STATE_PATH=") + env = append(env, "STATE_PATH="+statePath) ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -213,6 +214,8 @@ func ExecuteItemAction( item Item, action string, argv []string, + env []string, + statePath string, timeout time.Duration, ) (Item, error) { itemJson, err := json.Marshal(item) @@ -220,7 +223,7 @@ func ExecuteItemAction( return Item{}, fmt.Errorf("failed to serialize item: %v", err) } - res, err := Execute(item.Source, argv, nil, string(itemJson), time.Minute) + res, err := Execute(item.Source, argv, env, statePath, string(itemJson), timeout) if err != nil { return Item{}, fmt.Errorf("failed to execute %s for %s/%s: %v", action, item.Source, item.Id, err) } diff --git a/core/action_test.go b/core/action_test.go index 3546e9b..6e96124 100644 --- a/core/action_test.go +++ b/core/action_test.go @@ -72,7 +72,7 @@ func TestExecute(t *testing.T) { } } execute := func(argv []string) ([]Item, error) { - return Execute("_", argv, nil, "", time.Minute) + return Execute("_", argv, nil, "", "", time.Minute) } res, err := execute([]string{"true"}) @@ -89,7 +89,7 @@ func TestExecute(t *testing.T) { assertLen(res, 0) // Timeout - res, err = Execute("_", []string{"sleep", "10"}, nil, "", time.Millisecond) + res, err = Execute("_", []string{"sleep", "10"}, nil, "", "", time.Millisecond) assertNotNil(err) assertLen(res, 0) @@ -102,7 +102,7 @@ func TestExecute(t *testing.T) { } // Read from stdin - res, err = Execute("_", []string{"jq", "-cR", `{id: .}`}, nil, "bar", time.Minute) + res, err = Execute("_", []string{"jq", "-cR", `{id: .}`}, nil, "", "bar", time.Minute) assertNil(err) assertLen(res, 1) if res[0].Id != "bar" { @@ -110,7 +110,7 @@ func TestExecute(t *testing.T) { } // Set env - res, err = Execute("_", []string{"jq", "-cn", `{id: env.HELLO}`}, []string{"HELLO=baz"}, "", time.Minute) + res, err = Execute("_", []string{"jq", "-cn", `{id: env.HELLO}`}, []string{"HELLO=baz"}, "", "", time.Minute) assertNil(err) assertLen(res, 1) if res[0].Id != "baz" { diff --git a/core/source.go b/core/source.go index 37c18b7..232aed1 100644 --- a/core/source.go +++ b/core/source.go @@ -284,7 +284,7 @@ func UpdateWithFetchedItems(db *DB, source string, items []Item) (int, int, erro if err == nil { var updatedNewItems []Item for _, item := range newItems { - updatedItem, err := ExecuteItemAction(item, "on_create", onCreateArgv, time.Minute) + updatedItem, err := ExecuteItemAction(item, "on_create", onCreateArgv, nil, "", time.Minute) if err != nil { log.Printf("error: %v", err) } diff --git a/core/source_test.go b/core/source_test.go index fa49a51..3799d90 100644 --- a/core/source_test.go +++ b/core/source_test.go @@ -173,7 +173,7 @@ func TestOnCreateAction(t *testing.T) { } execute := func(argv []string) []Item { - items, err := Execute("test", argv, nil, "", time.Minute) + items, err := Execute("test", argv, nil, "", "", time.Minute) if err != nil { t.Fatal("unexpected error executing test fetch") } diff --git a/web/item.go b/web/item.go index 76e3a5d..1c4d45c 100644 --- a/web/item.go +++ b/web/item.go @@ -61,7 +61,7 @@ func (env *Env) doAction(writer http.ResponseWriter, req *http.Request) { return } - newItem, err := core.ExecuteItemAction(item, action, argv, time.Minute) + newItem, err := core.ExecuteItemAction(item, action, argv, nil, "", time.Minute) if err != nil { http.Error(writer, err.Error(), 500) return