示例#1
0
	"conduit/storage"
	"github.com/spf13/cobra"
)

var s string

// watchCmd represents the watch command
var watchCmd = &cobra.Command{
	Use:   "watch",
	Short: "Begin watching for commands.",
	Long: `Start processing the command queue. Conduit will run and wait for a
command to be delivered to it for processing.`,
	Run: func(cmd *cobra.Command, args []string) {
		log.Info("Starting...")
		q := queue.GetQueue()
		mgr := storage.GetStorage()
		for {
			cmd, err := q.Get()
			if err != nil {
				log.Error(err.Error())
			}
			if cmd != nil {
				scriptBody, err := mgr.GetScript(cmd.RemoteScriptUrl)
				if err != nil {
					log.Error(err.Error())
				} else {
					err := engine.Execute(scriptBody)
					if err != nil {
						log.Error(err.Error())
					} else {
						q.Delete(cmd)
示例#2
0
	"fmt"
	"github.com/spf13/cobra"
)

// sendCmd represents the send command
var sendCmd = &cobra.Command{
	Use:   "send [file] [client]",
	Short: "Send a script to be executed",
	Long: `Send a script to be executed by a client. The file can either be a
javascript file or a zip file containing a javascript file and other arbitrary
files.`,
	Run: func(cmd *cobra.Command, args []string) {
		q := queue.GetQueue()
		filename := args[0]
		client := args[1]
		storage := storage.GetStorage()
		err := storage.PutScript(filename)
		if err != nil {
			fmt.Println(err)
		}
		script := &queue.ScriptCommand{
			RemoteScriptUrl: filename,
			RemoteAssets:    []string{},
		}
		err = q.Put(client, script)
		if err != nil {
			fmt.Println(err)
		}
	},
}