Skip to content

Commit

Permalink
Added async run command
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Sep 6, 2024
1 parent 1687a16 commit 5cc5e5a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func makeServiceCmd() *cobra.Command {
serviceCmd.AddCommand(makeServicePutFileCmd())
serviceCmd.AddCommand(makeServiceListFilesCmd())
serviceCmd.AddCommand(makeServiceRunCmd())
serviceCmd.AddCommand(makeServiceJobCmd())

return serviceCmd
}
66 changes: 66 additions & 0 deletions cmd/service_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright (C) GRyCAP - I3M - UPV
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"errors"

"github.com/grycap/oscar-cli/pkg/config"
"github.com/grycap/oscar-cli/pkg/storage"
"github.com/spf13/cobra"
)

var DEFAULT_PROVIDER = "minio.default"

func serviceJobFunc(cmd *cobra.Command, args []string) error {
// Read the config file
conf, err := config.ReadConfig(configPath)
if err != nil {
return err
}

cluster, err := getCluster(cmd, conf)
if err != nil {
return err
}
// Parse input (only --input or --text-input are allowed) (AND one of them is required)
inputFilePath, _ := cmd.Flags().GetString("input")
if inputFilePath == "" {
return errors.New("you must specify \"--input\" or \"--text-input\" flag")
}
// Make the request
err = storage.PutFile(conf.Oscar[cluster], args[0], DEFAULT_PROVIDER, inputFilePath, "")
if err != nil {
return err
}

return nil
}

func makeServiceJobCmd() *cobra.Command {
serviceRunCmd := &cobra.Command{
Use: "job SERVICE_NAME --input",
Short: "Invoke a service asynchronously (only compatible with MinIO providers)",
Args: cobra.ExactArgs(1),
Aliases: []string{"job", "j"},
RunE: serviceRunFunc,
}

serviceRunCmd.Flags().StringP("file-input", "f", "", "input file for the request")

return serviceRunCmd
}
2 changes: 2 additions & 0 deletions cmd/service_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func serviceRunFunc(cmd *cobra.Command, args []string) error {

if endpoint != "" && token == "" {
// Error missing token
return errors.New("you must specify a service token with the flag \"--token\"")
}
if token != "" && endpoint == "" {
// Error missing endpoint
return errors.New("you must specify a the cluster endpoint with the flag \"--endpoint\"")
}
// Parse input (only --input or --text-input are allowed) (AND one of them is required)
inputFile, _ := cmd.Flags().GetString("input")
Expand Down

0 comments on commit 5cc5e5a

Please sign in to comment.