Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Trigger a build asynchronously #61

Merged
merged 1 commit into from
Apr 27, 2018
Merged

Trigger a build asynchronously #61

merged 1 commit into from
Apr 27, 2018

Conversation

dtheodor
Copy link
Contributor

@dtheodor dtheodor commented Apr 27, 2018

Add a mistry build --no-wait flag that triggers a build and exits without waiting

  • add a new client flag
  • update the server endpoint to accept POST /jobs?async, returns an empty 201 response on success
  • update README and CLI docs

Some small random improvements

  • use {{.HelpName}} and {{.Name}} in help templates to avoid hardcoding command names
  • add some comments to exported functions to stop go fmt complains
  • embed the JobRequest into the Job to avoid field declaration duplication

Closes #15


#### HTTP Endpoints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should place this under a wiki page and gradually enrich it.

project, group it under group_name, sync the result to the
directory /tmp/yarn and use the dynamic arguments yarn.lock and foo.
Note the @ before the yarn.lock, this indicates a referral to an actual file on the
filesystem.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this even more:

Schedule a job with a group and some parameters and put artifacts under /tmp/yarn using rsync. Prefixing a file name with @ will cause the contents of yarn.lock to be sent as parameters.


2. The following sequence uses the GROUP environment variable to set the project group.
2. Uses the GROUP environment variable to set the project group.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're at it, I think this example isn't needed at all. A note that says that every flag can be provided as environment variable too should be sufficient.

3. Schedules a build and exits early without waiting for the result by not
specifying a transport

$ {{.HelpName}} -host example.org --port 9090 --project yarn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need update.


app := cli.NewApp()
app.Name = "mistry-cli"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the .Name set automatically by urfave/cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

request, err := http.NewRequest("POST", fmt.Sprintf("http://%s:%s/%s", host, port, JobsPath), bytes.NewBuffer(jrJSON))
body, err := sendRequest(url, verbose, project, group, params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better construct the JobRequest before calling this function and just pass it as a parameter? The function would then would only do what it's supposed to.

t.Fatalf("mistry-cli stdout: %s, stderr: %s, err: %#v", cmdout, cmderr, err)
}
assertEq(cmdout, "", t)
assertEq(cmderr, "", t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should test here that the build has indeed run successfully.

@@ -57,6 +57,7 @@ const (
// Docker images/containers created by mistry.
ImgCntPrefix = "mistry-"

// DateFmt the date format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/DateFmt//

@@ -32,9 +32,7 @@ type Job struct {
ID string

// user-provided
Project string
Params types.Params
Group string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job is a core struct and should not get everything that a JobRequest has. In the future we might add more fields and methods to JobRequest but we don't want to add them here.

On the other hand, I see why you chose to do so and perhaps we should extract those common fields into yet another type called JobInfo maybe or something like that.

Anyway, I think we should leave this for another patch.

@@ -134,6 +144,12 @@ func (s *Server) HandleNewJob(w http.ResponseWriter, r *http.Request) {
}
}

func (s *Server) handleNewJobAsync(j *Job, w http.ResponseWriter) {
s.Log.Printf("Scheduling %s...", j)
defer s.Work(context.Background(), j)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to leave the connection open. You could just go s.Work this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I meant to go this

CHANGELOG.md Outdated
@@ -6,6 +6,7 @@ Breaking changes are prefixed with a "[BREAKING]" label.

### Added

- Asynchronous build scheduling [[#61](https://github.com/skroutz/mistry/pull/61)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/build/job/

@dtheodor dtheodor requested a review from apostergiou April 27, 2018 10:01
@agis
Copy link
Contributor

agis commented Apr 27, 2018

LGTM!

@dtheodor dtheodor merged commit 04c9353 into master Apr 27, 2018
@dtheodor dtheodor deleted the async-job branch April 27, 2018 13:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants