示例#1
0
文件: delete.go 项目: goodeggs/ccron
func cmdCronDelete(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Die(err)
	}

	server := stdcli.Server(c)

	id, err := strconv.Atoi(c.Args().First())

	if err != nil {
		stdcli.Die(err)
	}

	path := fmt.Sprintf("/apps/%s/jobs/%d", app, id)

	_, err = client.Request("DELETE", server, path, nil)

	if err != nil {
		stdcli.Die(err)
	}

	fmt.Printf("Deleted #%d\n", id)
}
示例#2
0
文件: create.go 项目: goodeggs/ccron
func cmdCronCreate(c *cli.Context) {
	_, app, err := stdcli.DirApp(c, ".")

	if err != nil {
		stdcli.Die(err)
	}

	server := stdcli.Server(c)
	path := fmt.Sprintf("/apps/%s/jobs", app)

	args, err := shellquote.Split(c.Args().First())

	if err != nil {
		stdcli.Die(err)
	}

	if len(args) < 6 {
		stdcli.DieWithUsage(c, fmt.Errorf("argument is not in crontab format: `%s`", c.Args().First()))
	}

	job := stdcli.Job{
		Schedule: strings.Join(args[0:5], " "),
		Command:  strings.Join(args[5:], " "),
		App:      app,
	}

	data, err := json.Marshal(job)

	if err != nil {
		stdcli.Die(err)
	}

	body, err := client.Request("POST", server, path, bytes.NewReader(data))

	if err != nil {
		stdcli.Die(err)
	}

	err = json.Unmarshal(body, &job)

	fmt.Printf("Created #%d\n", job.Id)
	stdcli.PrintJobs(job)
}