Skip to content

Commit

Permalink
job: add manual job type for job update
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu committed Sep 29, 2023
1 parent adfcea3 commit 1c1122a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tsuru/client/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *JobCreate) Flags() *gnuflag.FlagSet {
c.fs = gnuflag.NewFlagSet("", gnuflag.ExitOnError)
c.fs.StringVar(&c.plan, "plan", "", infoMessage)
c.fs.StringVar(&c.plan, "p", "", infoMessage)
schedule := "schedule string"
schedule := "Schedule string"
c.fs.StringVar(&c.schedule, "schedule", "", schedule)
c.fs.StringVar(&c.schedule, "s", "", schedule)
teamMessage := "Team owner job"
Expand Down Expand Up @@ -461,6 +461,7 @@ type JobUpdate struct {
pool string
description string
image string
manual bool
tags cmd.StringSliceFlag

fs *gnuflag.FlagSet
Expand All @@ -469,7 +470,7 @@ type JobUpdate struct {
func (c *JobUpdate) Info() *cmd.Info {
return &cmd.Info{
Name: "job-update",
Usage: "job update <job-name> [--image/-i <image>] [--plan/-p plan name] [--schedule/-s schedule name] [--team/-t team owner] [--pool/-o pool name] [--description/-d description] [--tag/-g tag]... -- [commands]",
Usage: "job update <job-name> [--image/-i <image>] [--plan/-p plan name] [--schedule/-s schedule name] [--manual] [--team/-t team owner] [--pool/-o pool name] [--description/-d description] [--tag/-g tag]... -- [commands]",
Desc: "Updates a job",
MinArgs: 1,
}
Expand All @@ -481,9 +482,11 @@ func (c *JobUpdate) Flags() *gnuflag.FlagSet {
c.fs = gnuflag.NewFlagSet("", gnuflag.ExitOnError)
c.fs.StringVar(&c.plan, "plan", "", infoMessage)
c.fs.StringVar(&c.plan, "p", "", infoMessage)
schedule := "schedule string"
schedule := "Schedule string"
c.fs.StringVar(&c.schedule, "schedule", "", schedule)
c.fs.StringVar(&c.schedule, "s", "", schedule)
manualMessage := "Manual job"
c.fs.BoolVar(&c.manual, "manual", false, manualMessage)
teamMessage := "Team owner job"
c.fs.StringVar(&c.teamOwner, "team", "", teamMessage)
c.fs.StringVar(&c.teamOwner, "t", "", teamMessage)
Expand Down Expand Up @@ -511,6 +514,9 @@ func (c *JobUpdate) Run(ctx *cmd.Context, cli *cmd.Client) error {
if err != nil {
return err
}
if c.manual && c.schedule != "" {
return errors.New("cannot set both manual job and schedule options")
}
var jobUpdateCommands []string
if len(ctx.Args) > 1 {
jobUpdateCommands, err = parseJobCommands(ctx.Args[1:])
Expand All @@ -522,6 +528,7 @@ func (c *JobUpdate) Run(ctx *cmd.Context, cli *cmd.Client) error {
Name: jobName,
Tags: c.tags,
Schedule: c.schedule,
Manual: c.manual,
Plan: c.plan,
Pool: c.pool,
Description: c.description,
Expand Down
14 changes: 14 additions & 0 deletions tsuru/client/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,20 @@ func (s *S) TestJobUpdateApiError(c *check.C) {
c.Assert(err.Error(), check.Equals, expected)
}

func (s *S) TestJobUpdateMutualScheduleAndManualError(c *check.C) {
var stdout, stderr bytes.Buffer
context := cmd.Context{
Args: []string{"failjob", "ubuntu:latest", "\"echo \"fail\"\""},
Stdout: &stdout,
Stderr: &stderr,
}
client := cmd.NewClient(&http.Client{Transport: &cmdtest.Transport{Status: 200}}, nil, manager)
command := JobUpdate{}
command.Flags().Parse(true, []string{"-t", "admin", "-o", "somepool", "-s", "* * * * *", "--manual"})
err := command.Run(&context, client)
c.Assert(err.Error(), check.Equals, "cannot set both manual job and schedule options")
}

func (s *S) TestJobLog(c *check.C) {
var stdout, stderr bytes.Buffer
context := cmd.Context{
Expand Down

0 comments on commit 1c1122a

Please sign in to comment.