Example #1
0
func cmdCron(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)

	body, err := client.Request("GET", server, path, nil)

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

	var jobs stdcli.Jobs
	err = json.Unmarshal(body, &jobs)

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

	stdcli.PrintJobs(jobs...)
}
Example #2
0
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)
}