{"action":"created","comment":{"url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/comments/45380726","id":45380726,"diff_hunk":"@@ -0,0 +1,194 @@\n+package main\n+\n+import (\n+\t\"encoding/json\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"os\"\n+\t\"strconv\"\n+\t\"strings\"\n+\n+\t\"github.com/gyminee/qwop/worker\"\n+\t\"github.com/wtlangford/go-desk/resource\"\n+\t\"github.com/wtlangford/go-desk/service\"\n+\t\"net/url\"\n+)\n+\n+// Topic to listen on\n+const Topic = \"user_updated\"\n+\n+// Channel to listen on\n+const Channel = \"desk\"\n+\n+// Name to lookup in config file\n+const Name = \"desk_user\"\n+\n+// DeskUserWorker sends user info to Desk\n+type DeskUserWorker struct {\n+\tworker.Worker\n+\tdeskConfig\n+\tclient *service.Client\n+}\n+\n+type deskConfig struct {\n+\tSiteURL        string `json:\"site_url\"`\n+\tConsumerKey    string `json:\"consumer_key\"`\n+\tConsumerSecret string `json:\"consumer_secret\"`\n+\tTokenKey       string `json:\"token_key\"`\n+\tTokenSecret    string `json:\"token_secret\"`\n+}\n+\n+// main run of the worker, initializes a WorkerCli and starts the worker run loop which listens for WorkerMessages on the appropriate NSQ topic/channel\n+func main() {\n+\tfmt.Println(\"Starting Desk User Worker.\")\n+\tdeskUserWorker, err := worker.NewWorkerCli(Name, NewDeskUserWorker)\n+\tif err != nil {\n+\t\tfmt.Println(\"Error initializing desk user worker: \", err)\n+\t\tos.Exit(0)\n+\t}\n+\tdeskUserWorker.Start()\n+}\n+\n+// ProcessTask is responsible for processing all incoming worker messages and responding with either nil or an error\n+func (w *DeskUserWorker) ProcessTask(wm worker.WorkerMessage) error {\n+\tw.Log(\"Desk user worker processing task\")\n+\tusers, ok := wm.Args[0].([]interface{})\n+\tif !ok {\n+\t\treturn errors.New(\"Invalid arguments\")\n+\t}\n+\tif w.client == nil {\n+\t\tw.client = service.NewClientWithOAuth(nil, w.deskConfig.SiteURL, w.deskConfig.ConsumerKey, w.deskConfig.ConsumerSecret, w.deskConfig.TokenKey, w.deskConfig.TokenSecret)\n+\t}\n+\tif len(users) == 0 {\n+\t\treturn errors.New(\"No users to update\")\n+\t}\n+\tvar endpoint string\n+\tif len(wm.Args) > 1 {\n+\t\tendpoint, _ = wm.Args[1].(string)\n+\t}\n+\n+\tidMap := make(map[string]string)\n+\tfor i, u := range users {\n+\t\tcustomerData, succ := u.(map[string]interface{})\n+\t\tif succ == false {\n+\t\t\treturn errors.New(\"User not a map?\")\n+\t\t}\n+\t\tcustomer := buildCustomer(customerData)\n+\t\tneedsUpdate := customer.GetId() == -1\n+\n+\t\tvar newCustomer *resource.Customer\n+\t\tvar err error\n+\t\tif w.findCustomer(&customer) {\n+\t\t\tnewCustomer, _, err = w.client.Customer.Update(&customer)\n+\t\t} else {\n+\t\t\tnewCustomer, _, err = w.client.Customer.Create(&customer)\n+\t\t}\n+\t\tif err != nil {\n+\t\t\tif i == 0 {\n+\t\t\t\t// Just retry this one as-is.\n+\t\t\t\treturn err\n+\t\t\t} else {\n+\t\t\t\t// Mark the ones that succeeded as complete in rails,\n+\t\t\t\t// requeue the ones that aren't complete,\n+\t\t\t\t// mark this task as complete\n+\t\t\t\tpayload := []interface{}{users[i:]}\n+\t\t\t\tif endpoint != \"\" {\n+\t\t\t\t\tw.updateRailsUsers(endpoint, idMap)\n+\t\t\t\t\tpayload = append(payload, endpoint)\n+\t\t\t\t}\n+\t\t\t\tw.Enqueue(Topic, payload)\n+\t\t\t\treturn nil\n+\t\t\t}\n+\t\t}\n+\t\tif needsUpdate {\n+\t\t\tdb_id, err := strconv.Atoi(*newCustomer.ExternalID)\n+\t\t\tif err == nil {\n+\t\t\t\tidMap[strconv.Itoa(db_id)] = strconv.Itoa(newCustomer.GetId())\n+\t\t\t}\n+\t\t}\n+\t}\n+\tif endpoint != \"\" {","path":"dbworkers/db_desk_user_worker.go","position":110,"original_position":110,"commit_id":"0662c111b416ed6d74042f018b5aa9e7f1899457","original_commit_id":"0662c111b416ed6d74042f018b5aa9e7f1899457","user":{"login":"neil-lobracco","id":2692263,"avatar_url":"https://avatars.githubusercontent.com/u/2692263?v=3","gravatar_id":"","url":"https://api.github.com/users/neil-lobracco","html_url":"https://github.com/neil-lobracco","followers_url":"https://api.github.com/users/neil-lobracco/followers","following_url":"https://api.github.com/users/neil-lobracco/following{/other_user}","gists_url":"https://api.github.com/users/neil-lobracco/gists{/gist_id}","starred_url":"https://api.github.com/users/neil-lobracco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neil-lobracco/subscriptions","organizations_url":"https://api.github.com/users/neil-lobracco/orgs","repos_url":"https://api.github.com/users/neil-lobracco/repos","events_url":"https://api.github.com/users/neil-lobracco/events{/privacy}","received_events_url":"https://api.github.com/users/neil-lobracco/received_events","type":"User","site_admin":false},"body":"Perhaps `&& len(idMap) > 0`?","created_at":"2015-11-19T18:35:37Z","updated_at":"2015-11-19T18:35:37Z","html_url":"https://github.com/dailyburn/db-qwop-workers/pull/6#discussion_r45380726","pull_request_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/comments/45380726"},"html":{"href":"https://github.com/dailyburn/db-qwop-workers/pull/6#discussion_r45380726"},"pull_request":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6","id":51255116,"html_url":"https://github.com/dailyburn/db-qwop-workers/pull/6","diff_url":"https://github.com/dailyburn/db-qwop-workers/pull/6.diff","patch_url":"https://github.com/dailyburn/db-qwop-workers/pull/6.patch","issue_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/6","number":6,"state":"open","locked":false,"title":"Add new desk user update worker","user":{"login":"wtlangford","id":3422295,"avatar_url":"https://avatars.githubusercontent.com/u/3422295?v=3","gravatar_id":"","url":"https://api.github.com/users/wtlangford","html_url":"https://github.com/wtlangford","followers_url":"https://api.github.com/users/wtlangford/followers","following_url":"https://api.github.com/users/wtlangford/following{/other_user}","gists_url":"https://api.github.com/users/wtlangford/gists{/gist_id}","starred_url":"https://api.github.com/users/wtlangford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wtlangford/subscriptions","organizations_url":"https://api.github.com/users/wtlangford/orgs","repos_url":"https://api.github.com/users/wtlangford/repos","events_url":"https://api.github.com/users/wtlangford/events{/privacy}","received_events_url":"https://api.github.com/users/wtlangford/received_events","type":"User","site_admin":false},"body":"Modify intercom user update worker to use new format as well as new version of\r\nthe intercom package for built-in bulk operations.","created_at":"2015-11-19T17:37:27Z","updated_at":"2015-11-19T18:35:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b208c4dca66ba0bb9d30c9b07a15a76ea14423e4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6/commits","review_comments_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6/comments","review_comment_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/6/comments","statuses_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/statuses/0662c111b416ed6d74042f018b5aa9e7f1899457","head":{"label":"dailyburn:extract-desk","ref":"extract-desk","sha":"0662c111b416ed6d74042f018b5aa9e7f1899457","user":{"login":"dailyburn","id":4315326,"avatar_url":"https://avatars.githubusercontent.com/u/4315326?v=3","gravatar_id":"","url":"https://api.github.com/users/dailyburn","html_url":"https://github.com/dailyburn","followers_url":"https://api.github.com/users/dailyburn/followers","following_url":"https://api.github.com/users/dailyburn/following{/other_user}","gists_url":"https://api.github.com/users/dailyburn/gists{/gist_id}","starred_url":"https://api.github.com/users/dailyburn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dailyburn/subscriptions","organizations_url":"https://api.github.com/users/dailyburn/orgs","repos_url":"https://api.github.com/users/dailyburn/repos","events_url":"https://api.github.com/users/dailyburn/events{/privacy}","received_events_url":"https://api.github.com/users/dailyburn/received_events","type":"Organization","site_admin":false},"repo":{"id":14205773,"name":"db-qwop-workers","full_name":"dailyburn/db-qwop-workers","owner":{"login":"dailyburn","id":4315326,"avatar_url":"https://avatars.githubusercontent.com/u/4315326?v=3","gravatar_id":"","url":"https://api.github.com/users/dailyburn","html_url":"https://github.com/dailyburn","followers_url":"https://api.github.com/users/dailyburn/followers","following_url":"https://api.github.com/users/dailyburn/following{/other_user}","gists_url":"https://api.github.com/users/dailyburn/gists{/gist_id}","starred_url":"https://api.github.com/users/dailyburn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dailyburn/subscriptions","organizations_url":"https://api.github.com/users/dailyburn/orgs","repos_url":"https://api.github.com/users/dailyburn/repos","events_url":"https://api.github.com/users/dailyburn/events{/privacy}","received_events_url":"https://api.github.com/users/dailyburn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dailyburn/db-qwop-workers","description":"DailyBurn QWOP Worker implementations","fork":false,"url":"https://api.github.com/repos/dailyburn/db-qwop-workers","forks_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/forks","keys_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/teams","hooks_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/hooks","issue_events_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/events{/number}","events_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/events","assignees_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/assignees{/user}","branches_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/branches{/branch}","tags_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/tags","blobs_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/refs{/sha}","trees_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/statuses/{sha}","languages_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/languages","stargazers_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/stargazers","contributors_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/contributors","subscribers_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/subscribers","subscription_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/subscription","commits_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/commits{/sha}","git_commits_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/commits{/sha}","comments_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/comments{/number}","issue_comment_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/comments{/number}","contents_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/contents/{+path}","compare_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/merges","archive_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/downloads","issues_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues{/number}","pulls_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls{/number}","milestones_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/milestones{/number}","notifications_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/labels{/name}","releases_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/releases{/id}","created_at":"2013-11-07T14:28:05Z","updated_at":"2015-04-22T16:43:04Z","pushed_at":"2015-11-19T17:37:27Z","git_url":"git://github.com/dailyburn/db-qwop-workers.git","ssh_url":"git@github.com:dailyburn/db-qwop-workers.git","clone_url":"https://github.com/dailyburn/db-qwop-workers.git","svn_url":"https://github.com/dailyburn/db-qwop-workers","homepage":null,"size":54,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"dailyburn:master","ref":"master","sha":"acce06e29f1348e29d1ee2da28335805fde5dfca","user":{"login":"dailyburn","id":4315326,"avatar_url":"https://avatars.githubusercontent.com/u/4315326?v=3","gravatar_id":"","url":"https://api.github.com/users/dailyburn","html_url":"https://github.com/dailyburn","followers_url":"https://api.github.com/users/dailyburn/followers","following_url":"https://api.github.com/users/dailyburn/following{/other_user}","gists_url":"https://api.github.com/users/dailyburn/gists{/gist_id}","starred_url":"https://api.github.com/users/dailyburn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dailyburn/subscriptions","organizations_url":"https://api.github.com/users/dailyburn/orgs","repos_url":"https://api.github.com/users/dailyburn/repos","events_url":"https://api.github.com/users/dailyburn/events{/privacy}","received_events_url":"https://api.github.com/users/dailyburn/received_events","type":"Organization","site_admin":false},"repo":{"id":14205773,"name":"db-qwop-workers","full_name":"dailyburn/db-qwop-workers","owner":{"login":"dailyburn","id":4315326,"avatar_url":"https://avatars.githubusercontent.com/u/4315326?v=3","gravatar_id":"","url":"https://api.github.com/users/dailyburn","html_url":"https://github.com/dailyburn","followers_url":"https://api.github.com/users/dailyburn/followers","following_url":"https://api.github.com/users/dailyburn/following{/other_user}","gists_url":"https://api.github.com/users/dailyburn/gists{/gist_id}","starred_url":"https://api.github.com/users/dailyburn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dailyburn/subscriptions","organizations_url":"https://api.github.com/users/dailyburn/orgs","repos_url":"https://api.github.com/users/dailyburn/repos","events_url":"https://api.github.com/users/dailyburn/events{/privacy}","received_events_url":"https://api.github.com/users/dailyburn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dailyburn/db-qwop-workers","description":"DailyBurn QWOP Worker implementations","fork":false,"url":"https://api.github.com/repos/dailyburn/db-qwop-workers","forks_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/forks","keys_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/teams","hooks_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/hooks","issue_events_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/events{/number}","events_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/events","assignees_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/assignees{/user}","branches_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/branches{/branch}","tags_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/tags","blobs_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/refs{/sha}","trees_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/statuses/{sha}","languages_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/languages","stargazers_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/stargazers","contributors_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/contributors","subscribers_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/subscribers","subscription_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/subscription","commits_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/commits{/sha}","git_commits_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/git/commits{/sha}","comments_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/comments{/number}","issue_comment_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/comments{/number}","contents_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/contents/{+path}","compare_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/merges","archive_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/downloads","issues_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues{/number}","pulls_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls{/number}","milestones_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/milestones{/number}","notifications_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/labels{/name}","releases_url":"https://api.github.com/repos/dailyburn/db-qwop-workers/releases{/id}","created_at":"2013-11-07T14:28:05Z","updated_at":"2015-04-22T16:43:04Z","pushed_at":"2015-11-19T17:37:27Z","git_url":"git://github.com/dailyburn/db-qwop-workers.git","ssh_url":"git@github.com:dailyburn/db-qwop-workers.git","clone_url":"https://github.com/dailyburn/db-qwop-workers.git","svn_url":"https://github.com/dailyburn/db-qwop-workers","homepage":null,"size":54,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6"},"html":{"href":"https://github.com/dailyburn/db-qwop-workers/pull/6"},"issue":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/6"},"comments":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/dailyburn/db-qwop-workers/statuses/0662c111b416ed6d74042f018b5aa9e7f1899457"}}}}