{"action":"created","comment":{"url":"https://api.github.com/repos/flynn/flynn/pulls/comments/22595664","id":22595664,"diff_hunk":"@@ -0,0 +1,406 @@\n+package main\n+\n+import (\n+\t\"encoding/json\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"log\"\n+\t\"net/http\"\n+\t\"os\"\n+\t\"strconv\"\n+\t\"time\"\n+\n+\t\"github.com/flynn/flynn/Godeps/_workspace/src/github.com/bgentry/que-go\"\n+\t\"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-sql\"\n+\t\"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/pq\"\n+\t\"github.com/flynn/flynn/Godeps/_workspace/src/github.com/jackc/pgx\"\n+\t\"github.com/flynn/flynn/Godeps/_workspace/src/github.com/julienschmidt/httprouter\"\n+\t\"github.com/flynn/flynn/controller/client\"\n+\t\"github.com/flynn/flynn/deployer/strategies\"\n+\t\"github.com/flynn/flynn/deployer/types\"\n+\t\"github.com/flynn/flynn/discoverd/client\"\n+\t\"github.com/flynn/flynn/pkg/postgres\"\n+\t\"github.com/flynn/flynn/pkg/random\"\n+)\n+\n+var q *que.Client\n+var db *postgres.DB\n+var client *controller.Client\n+\n+var ErrNotFound = errors.New(\"deployer: resource not found\")\n+\n+type deployID struct {\n+\tID string\n+}\n+\n+func main() {\n+\tvar err error\n+\tclient, err = controller.NewClient(\"\", os.Getenv(\"CONTROLLER_AUTH_KEY\"))\n+\tif err != nil {\n+\t\tlog.Fatalln(\"Unable to connect to controller:\", err)\n+\t}\n+\n+\tport := os.Getenv(\"PORT\")\n+\tif port == \"\" {\n+\t\tport = \"4000\"\n+\t}\n+\n+\taddr := \":\" + port\n+\tif err := discoverd.Register(\"flynn-deployer\", addr); err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tpostgres.Wait(\"\")\n+\tdb, err = postgres.Open(\"\", \"\")\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tif err := migrateDB(db.DB); err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tpgxcfg, err := pgx.ParseURI(fmt.Sprintf(\"http://%s:%s@%s/%s\", os.Getenv(\"PGUSER\"), os.Getenv(\"PGPASSWORD\"), db.Addr(), os.Getenv(\"PGDATABASE\")))\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tpgxpool, err := pgx.NewConnPool(pgx.ConnPoolConfig{\n+\t\tConnConfig:   pgxcfg,\n+\t\tAfterConnect: que.PrepareStatements,\n+\t})\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\tdefer pgxpool.Close()\n+\n+\tq = que.NewClient(pgxpool)\n+\twm := que.WorkMap{\n+\t\t\"Deployment\": handleJob,\n+\t}\n+\n+\t// TODO start new worker on error\n+\tworkers := que.NewWorkerPool(q, wm, 10)\n+\tgo workers.Start()\n+\tdefer workers.Shutdown()\n+\n+\trouter := httprouter.New()\n+\trouter.POST(\"/deployments\", createDeployment)\n+\trouter.GET(\"/deployments/:deployment_id/events\", streamDeploymentEvents)\n+\n+\tlog.Println(\"Listening for HTTP requests on\", addr)\n+\tlog.Fatal(http.ListenAndServe(addr, router))\n+}\n+\n+func handleJob(job *que.Job) (e error) {\n+\tvar args deployID\n+\tif err := json.Unmarshal(job.Args, &args); err != nil {\n+\t\t// TODO: log error\n+\t\treturn err\n+\t}\n+\tid := args.ID\n+\tdeployment, err := getDeployment(id)\n+\tif err != nil {\n+\t\t// TODO: log error\n+\t\treturn err\n+\t}\n+\t// for recovery purposes, fetch old formation\n+\tf, err := client.GetFormation(deployment.AppID, deployment.OldReleaseID)\n+\tif err != nil {\n+\t\t// TODO: log error\n+\t\treturn err\n+\t}\n+\tsetDeploymentStatus(id, deployer.StatusRunning)\n+\tstrategy, err := strategy.GetStrategy(deployment.Strategy, client)\n+\tif err != nil {\n+\t\t// TODO: log error\n+\t\treturn err\n+\t}\n+\tevents := make(chan deployer.DeploymentEvent)\n+\tdefer close(events)\n+\tgo func() {\n+\t\tfor ev := range events {\n+\t\t\tev.DeploymentID = deployment.ID\n+\t\t\tsendDeploymentEvent(ev)\n+\t\t}\n+\t}()\n+\tdefer func() {\n+\t\t// rollback failed deploy\n+\t\tif e != nil {","path":"deployer/server.go","position":129,"original_position":129,"commit_id":"090d9dfdc0a302f5c4cdcf7723f69c08aefd0d16","original_commit_id":"090d9dfdc0a302f5c4cdcf7723f69c08aefd0d16","user":{"login":"lmars","id":488515,"avatar_url":"https://avatars.githubusercontent.com/u/488515?v=3","gravatar_id":"","url":"https://api.github.com/users/lmars","html_url":"https://github.com/lmars","followers_url":"https://api.github.com/users/lmars/followers","following_url":"https://api.github.com/users/lmars/following{/other_user}","gists_url":"https://api.github.com/users/lmars/gists{/gist_id}","starred_url":"https://api.github.com/users/lmars/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmars/subscriptions","organizations_url":"https://api.github.com/users/lmars/orgs","repos_url":"https://api.github.com/users/lmars/repos","events_url":"https://api.github.com/users/lmars/events{/privacy}","received_events_url":"https://api.github.com/users/lmars/received_events","type":"User","site_admin":false},"body":"I think this should be `deployErr`, or maybe just `err`","created_at":"2015-01-07T16:16:42Z","updated_at":"2015-01-07T16:16:42Z","html_url":"https://github.com/flynn/flynn/pull/666#discussion_r22595664","pull_request_url":"https://api.github.com/repos/flynn/flynn/pulls/666","_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments/22595664"},"html":{"href":"https://github.com/flynn/flynn/pull/666#discussion_r22595664"},"pull_request":{"href":"https://api.github.com/repos/flynn/flynn/pulls/666"}}},"pull_request":{"url":"https://api.github.com/repos/flynn/flynn/pulls/666","id":26610385,"html_url":"https://github.com/flynn/flynn/pull/666","diff_url":"https://github.com/flynn/flynn/pull/666.diff","patch_url":"https://github.com/flynn/flynn/pull/666.patch","issue_url":"https://api.github.com/repos/flynn/flynn/issues/666","number":666,"state":"open","locked":false,"title":"Deployer","user":{"login":"archSeer","id":1372918,"avatar_url":"https://avatars.githubusercontent.com/u/1372918?v=3","gravatar_id":"","url":"https://api.github.com/users/archSeer","html_url":"https://github.com/archSeer","followers_url":"https://api.github.com/users/archSeer/followers","following_url":"https://api.github.com/users/archSeer/following{/other_user}","gists_url":"https://api.github.com/users/archSeer/gists{/gist_id}","starred_url":"https://api.github.com/users/archSeer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/archSeer/subscriptions","organizations_url":"https://api.github.com/users/archSeer/orgs","repos_url":"https://api.github.com/users/archSeer/repos","events_url":"https://api.github.com/users/archSeer/events{/privacy}","received_events_url":"https://api.github.com/users/archSeer/received_events","type":"User","site_admin":false},"body":"Adds a deployer component, which uses the bgentry/que-go to schedule deployments using different strategies (currently one-by-one or all-at-once).\r\n\r\nResolves #602, resolves #603.","created_at":"2014-12-27T02:46:58Z","updated_at":"2015-01-07T16:16:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a490315358f946aa3a306c88759ad3dbd3b8e6b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/flynn/flynn/pulls/666/commits","review_comments_url":"https://api.github.com/repos/flynn/flynn/pulls/666/comments","review_comment_url":"https://api.github.com/repos/flynn/flynn/pulls/comments/{number}","comments_url":"https://api.github.com/repos/flynn/flynn/issues/666/comments","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/090d9dfdc0a302f5c4cdcf7723f69c08aefd0d16","head":{"label":"flynn:deploy-strategy","ref":"deploy-strategy","sha":"090d9dfdc0a302f5c4cdcf7723f69c08aefd0d16","user":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"repo":{"id":11290232,"name":"flynn","full_name":"flynn/flynn","owner":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flynn/flynn","description":"A next generation open source platform as a service (PaaS)","fork":false,"url":"https://api.github.com/repos/flynn/flynn","forks_url":"https://api.github.com/repos/flynn/flynn/forks","keys_url":"https://api.github.com/repos/flynn/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flynn/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flynn/flynn/teams","hooks_url":"https://api.github.com/repos/flynn/flynn/hooks","issue_events_url":"https://api.github.com/repos/flynn/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/flynn/flynn/events","assignees_url":"https://api.github.com/repos/flynn/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/flynn/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/flynn/flynn/tags","blobs_url":"https://api.github.com/repos/flynn/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flynn/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flynn/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/flynn/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/flynn/flynn/languages","stargazers_url":"https://api.github.com/repos/flynn/flynn/stargazers","contributors_url":"https://api.github.com/repos/flynn/flynn/contributors","subscribers_url":"https://api.github.com/repos/flynn/flynn/subscribers","subscription_url":"https://api.github.com/repos/flynn/flynn/subscription","commits_url":"https://api.github.com/repos/flynn/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/flynn/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/flynn/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/flynn/flynn/issues/comments/{number}","contents_url":"https://api.github.com/repos/flynn/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/flynn/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flynn/flynn/merges","archive_url":"https://api.github.com/repos/flynn/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flynn/flynn/downloads","issues_url":"https://api.github.com/repos/flynn/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/flynn/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/flynn/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/flynn/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flynn/flynn/labels{/name}","releases_url":"https://api.github.com/repos/flynn/flynn/releases{/id}","created_at":"2013-07-09T18:22:06Z","updated_at":"2015-01-07T15:29:58Z","pushed_at":"2015-01-07T15:29:59Z","git_url":"git://github.com/flynn/flynn.git","ssh_url":"git@github.com:flynn/flynn.git","clone_url":"https://github.com/flynn/flynn.git","svn_url":"https://github.com/flynn/flynn","homepage":"https://flynn.io","size":21361,"stargazers_count":3089,"watchers_count":3089,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":187,"mirror_url":null,"open_issues_count":99,"forks":187,"open_issues":99,"watchers":3089,"default_branch":"master"}},"base":{"label":"flynn:deployer-review-temp","ref":"deployer-review-temp","sha":"cdd13ab5f2c23514aedb53e23ccee7606c90517f","user":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"repo":{"id":11290232,"name":"flynn","full_name":"flynn/flynn","owner":{"login":"flynn","id":4973613,"avatar_url":"https://avatars.githubusercontent.com/u/4973613?v=3","gravatar_id":"","url":"https://api.github.com/users/flynn","html_url":"https://github.com/flynn","followers_url":"https://api.github.com/users/flynn/followers","following_url":"https://api.github.com/users/flynn/following{/other_user}","gists_url":"https://api.github.com/users/flynn/gists{/gist_id}","starred_url":"https://api.github.com/users/flynn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flynn/subscriptions","organizations_url":"https://api.github.com/users/flynn/orgs","repos_url":"https://api.github.com/users/flynn/repos","events_url":"https://api.github.com/users/flynn/events{/privacy}","received_events_url":"https://api.github.com/users/flynn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/flynn/flynn","description":"A next generation open source platform as a service (PaaS)","fork":false,"url":"https://api.github.com/repos/flynn/flynn","forks_url":"https://api.github.com/repos/flynn/flynn/forks","keys_url":"https://api.github.com/repos/flynn/flynn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flynn/flynn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flynn/flynn/teams","hooks_url":"https://api.github.com/repos/flynn/flynn/hooks","issue_events_url":"https://api.github.com/repos/flynn/flynn/issues/events{/number}","events_url":"https://api.github.com/repos/flynn/flynn/events","assignees_url":"https://api.github.com/repos/flynn/flynn/assignees{/user}","branches_url":"https://api.github.com/repos/flynn/flynn/branches{/branch}","tags_url":"https://api.github.com/repos/flynn/flynn/tags","blobs_url":"https://api.github.com/repos/flynn/flynn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flynn/flynn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flynn/flynn/git/refs{/sha}","trees_url":"https://api.github.com/repos/flynn/flynn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flynn/flynn/statuses/{sha}","languages_url":"https://api.github.com/repos/flynn/flynn/languages","stargazers_url":"https://api.github.com/repos/flynn/flynn/stargazers","contributors_url":"https://api.github.com/repos/flynn/flynn/contributors","subscribers_url":"https://api.github.com/repos/flynn/flynn/subscribers","subscription_url":"https://api.github.com/repos/flynn/flynn/subscription","commits_url":"https://api.github.com/repos/flynn/flynn/commits{/sha}","git_commits_url":"https://api.github.com/repos/flynn/flynn/git/commits{/sha}","comments_url":"https://api.github.com/repos/flynn/flynn/comments{/number}","issue_comment_url":"https://api.github.com/repos/flynn/flynn/issues/comments/{number}","contents_url":"https://api.github.com/repos/flynn/flynn/contents/{+path}","compare_url":"https://api.github.com/repos/flynn/flynn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flynn/flynn/merges","archive_url":"https://api.github.com/repos/flynn/flynn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flynn/flynn/downloads","issues_url":"https://api.github.com/repos/flynn/flynn/issues{/number}","pulls_url":"https://api.github.com/repos/flynn/flynn/pulls{/number}","milestones_url":"https://api.github.com/repos/flynn/flynn/milestones{/number}","notifications_url":"https://api.github.com/repos/flynn/flynn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flynn/flynn/labels{/name}","releases_url":"https://api.github.com/repos/flynn/flynn/releases{/id}","created_at":"2013-07-09T18:22:06Z","updated_at":"2015-01-07T15:29:58Z","pushed_at":"2015-01-07T15:29:59Z","git_url":"git://github.com/flynn/flynn.git","ssh_url":"git@github.com:flynn/flynn.git","clone_url":"https://github.com/flynn/flynn.git","svn_url":"https://github.com/flynn/flynn","homepage":"https://flynn.io","size":21361,"stargazers_count":3089,"watchers_count":3089,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":187,"mirror_url":null,"open_issues_count":99,"forks":187,"open_issues":99,"watchers":3089,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/flynn/flynn/pulls/666"},"html":{"href":"https://github.com/flynn/flynn/pull/666"},"issue":{"href":"https://api.github.com/repos/flynn/flynn/issues/666"},"comments":{"href":"https://api.github.com/repos/flynn/flynn/issues/666/comments"},"review_comments":{"href":"https://api.github.com/repos/flynn/flynn/pulls/666/comments"},"review_comment":{"href":"https://api.github.com/repos/flynn/flynn/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/flynn/flynn/pulls/666/commits"},"statuses":{"href":"https://api.github.com/repos/flynn/flynn/statuses/090d9dfdc0a302f5c4cdcf7723f69c08aefd0d16"}}}}