|
| 1 | +/* |
| 2 | + * Copyright 2024 Function Stream Org. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package reload |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "fmt" |
| 22 | + adminclient "github.com/functionstream/function-stream/admin/client" |
| 23 | + "github.com/functionstream/function-stream/cmd/client/common" |
| 24 | + "github.com/spf13/cobra" |
| 25 | + "os" |
| 26 | +) |
| 27 | + |
| 28 | +var Cmd = &cobra.Command{ |
| 29 | + Use: "reload", |
| 30 | + Short: "Reload Functions", |
| 31 | + Long: `Reload functions from the function store`, |
| 32 | + Args: cobra.NoArgs, |
| 33 | + Run: exec, |
| 34 | +} |
| 35 | + |
| 36 | +func exec(_ *cobra.Command, _ []string) { |
| 37 | + cfg := adminclient.NewConfiguration() |
| 38 | + cfg.Servers = []adminclient.ServerConfiguration{{ |
| 39 | + URL: common.Config.ServiceAddr, |
| 40 | + }} |
| 41 | + cli := adminclient.NewAPIClient(cfg) |
| 42 | + |
| 43 | + res, err := cli.FunctionStoreAPI.ReloadFunctions(context.Background()).Execute() |
| 44 | + if err != nil { |
| 45 | + fmt.Printf("Failed to reload functions: %v\n", err) |
| 46 | + os.Exit(1) |
| 47 | + } |
| 48 | + if res.StatusCode != 200 { |
| 49 | + fmt.Printf("Failed to reload functions with status code: %d\n", res.StatusCode) |
| 50 | + os.Exit(1) |
| 51 | + } |
| 52 | +} |
0 commit comments