command

package
v0.0.0-...-e228f7a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeleteCommand = cli.Command{
	Name:    "delete",
	Aliases: []string{"del"},
	Usage:   "delete a task",
	Action: func(c *cli.Context) error {

		if c.NArg() == 0 {
			return errors.New("must specify task id")
		}
		taskId := c.Args().Get(0)
		schedulerClient, err := client.NewClient()
		if err != nil {
			return err
		}
		err = schedulerClient.Delete(taskId)
		return err
	},
}
View Source
var GetCommand = cli.Command{
	Name:    "get",
	Aliases: []string{"g"},
	Usage:   "get results of a task",
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "watch",
			Usage: "watch task results",
		},
	},
	Action: func(c *cli.Context) error {

		if c.NArg() == 0 {
			return errors.New("must specify task id")
		}
		taskId := c.Args().Get(0)
		schedulerClient, err := client.NewClient()
		if err != nil {
			return err
		}

		watch := c.Bool("watch")

		task, err := schedulerClient.Get(taskId, false, 0)
		if err != nil {
			return err
		}
		task.PrintMe()

		if watch {
			for {
				fmt.Println("------------------------------------")
				version := task.Version
				task, err = schedulerClient.Get(taskId, watch, version)
				if err != nil {
					return err
				}
				task.PrintMe()
			}
		}
		return nil
	},
}
View Source
var ListCommand = cli.Command{
	Name:    "list",
	Aliases: []string{"l"},
	Usage:   "list all tasks",
	Action: func(c *cli.Context) error {
		schedulerClient, err := client.NewClient()
		if err != nil {
			return err
		}
		tasks, err := schedulerClient.List()
		if err != nil {
			return err
		}
		if len(tasks) == 0 {
			fmt.Println("no tasks")
			return nil
		}

		w := tabwriter.NewWriter(os.Stdout, 15, 1, 3, ' ', 0)
		fmt.Fprint(w, "Id\tTaskType\tTime\tScript\tStatus\tLastStatusUpdated\n")
		for _, item := range tasks {
			fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
				item.Id,
				item.TaskType,
				item.Time,
				item.Script,
				item.Status.String(),
				item.LastStatusUpdated)
		}
		if err := w.Flush(); err != nil {
			return err
		}
		return nil
	},
}
View Source
var StopCommand = cli.Command{
	Name:    "stop",
	Aliases: []string{"s"},
	Usage:   "stop a task",
	Action: func(c *cli.Context) error {

		if c.NArg() == 0 {
			return errors.New("must specify task id")
		}
		taskId := c.Args().Get(0)
		schedulerClient, err := client.NewClient()
		if err != nil {
			return err
		}
		err = schedulerClient.Stop(taskId)
		return err
	},
}
View Source
var SubmitCommand = cli.Command{
	Name:    "submit",
	Aliases: []string{"s"},
	Usage:   "submit a task",
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "type",
			Usage: "task type: delay or cron",
		},
		cli.DurationFlag{
			Name:  "time",
			Usage: "time",
		},
		cli.StringFlag{
			Name:  "script",
			Usage: "shell script",
		},
	},
	Action: func(c *cli.Context) error {

		if c.NArg() == 0 {
			return errors.New("must specify task id")
		}
		taskId := c.Args().Get(0)
		if taskId == "" {
			return errors.New("task id can not be blank")
		}

		taskType := c.String("type")
		if taskType != "delay" && taskType != "cron" {
			return errors.New("must specify task type with -type=delay/cron")
		}

		time := c.Duration("time")

		script := c.String("script")
		if script == "" {
			return errors.New("script can not be blank")
		}

		schedulerClient, err := client.NewClient()
		if err != nil {
			return err
		}
		task := common.NewTask(taskId, taskType, time, script)

		err = schedulerClient.Submit(task)
		return err
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL