{"action":"created","comment":{"url":"https://api.github.com/repos/levenlabs/goutil/pulls/comments/74990082","id":74990082,"diff_hunk":"@@ -0,0 +1,180 @@\n+package main\n+\n+import (\n+\t\"sort\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/levenlabs/go-llog\"\n+\t\"github.com/levenlabs/golib/genapi\"\n+\t\"github.com/levenlabs/golib/radixutil\"\n+\t\"github.com/mediocregopher/lever\"\n+\t\"github.com/mediocregopher/okq-go.v2\"\n+\t\"github.com/mediocregopher/radix.v2/pool\"\n+)\n+\n+var ga = genapi.GenAPI{\n+\tName: \"okq-fwd\",\n+\tLeverParams: []lever.Param{\n+\t\t{\n+\t\t\tName:        \"--src-okq-addr\",\n+\t\t\tDescription: \"Address of okq instance to pull jobs from\",\n+\t\t\tDefault:     \"127.0.0.1:4777\",\n+\t\t},\n+\t\t{\n+\t\t\tName:        \"--src-okq-pool-size\",\n+\t\t\tDescription: \"Number of connections to make to --src-okq-addr\",\n+\t\t\tDefault:     \"10\",\n+\t\t},\n+\t\t{\n+\t\t\tName:        \"--dst-okq-addr\",\n+\t\t\tDescription: \"(Required) Address of okq instance to forward jobs to\",\n+\t\t},\n+\t\t{\n+\t\t\tName:        \"--dst-okq-pool-size\",\n+\t\t\tDescription: \"Number of connections to make to --dst-okq-addr\",\n+\t\t\tDefault:     \"10\",\n+\t\t},\n+\t},\n+}\n+\n+const notifyTimeout = 30 * time.Second\n+\n+// copied pretty much directly from genapi. Once genapi.v2 (or whatever it ends\n+// up being called) is usable we won't have to do this\n+func okqClient(addr string, size int) *okq.Client {\n+\tkv := llog.KV{\n+\t\t\"addr\":     addr,\n+\t\t\"poolSize\": size,\n+\t}\n+\n+\tdf := radixutil.SRVDialFunc(ga.SRVClient, notifyTimeout)\n+\n+\tllog.Info(\"connecting to okq\", kv)\n+\tp, err := pool.NewCustom(\"tcp\", addr, size, df)\n+\tif err != nil {\n+\t\tllog.Fatal(\"error connecting to okq\", kv, llog.ErrKV(err))\n+\t}\n+\n+\treturn okq.NewWithOpts(okq.Opts{\n+\t\tRedisPool:     p,\n+\t\tNotifyTimeout: notifyTimeout,\n+\t})\n+}\n+\n+var src, dst *okq.Client\n+var queueNames []string\n+var queueNamesL sync.RWMutex\n+\n+func getQueueNames() ([]string, error) {\n+\tqq, err := src.Status()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tnames := make([]string, len(qq))\n+\tfor i, q := range qq {\n+\t\tnames[i] = q.Name\n+\t}\n+\tsort.Strings(names)\n+\treturn names, nil\n+}\n+\n+// Returns true if the given list of names is different than the active one\n+func queueNamesChanged(names []string) bool {\n+\tqueueNamesL.RLock()\n+\tcurNames := queueNames\n+\tqueueNamesL.RUnlock()\n+\n+\tif len(curNames) != len(names) {\n+\t\treturn true\n+\t}\n+\tfor i := range curNames {\n+\t\tif curNames[i] != names[i] {\n+\t\t\treturn true\n+\t\t}\n+\t}\n+\treturn false\n+}\n+\n+func main() {\n+\tga.CLIMode()\n+\tsrcAddr, _ := ga.ParamStr(\"--src-okq-addr\")\n+\tsrcPoolSize, _ := ga.ParamInt(\"--src-okq-pool-size\")\n+\tdstAddr, _ := ga.ParamStr(\"--dst-okq-addr\")\n+\tdstPoolSize, _ := ga.ParamInt(\"--dst-okq-pool-size\")\n+\n+\tif dstAddr == \"\" {\n+\t\tllog.Fatal(\"--dst-okq-addr is required\")\n+\t}\n+\n+\tsrc, dst = okqClient(srcAddr, srcPoolSize), okqClient(dstAddr, dstPoolSize)\n+\n+\t// Do an initial call to populate queue names before anything else needs it,\n+\t// then set up a spinner to continuously update it after\n+\tvar err error\n+\tif queueNames, err = getQueueNames(); err != nil {\n+\t\tllog.Fatal(\"could not get queue names\", llog.ErrKV(err))\n+\t}\n+\tgo func() {\n+\t\ttick := time.Tick(5 * time.Second)\n+\t\tfor {\n+\t\t\tif names, err := getQueueNames(); err != nil {\n+\t\t\t\tllog.Warn(\"could not get queue names\", llog.ErrKV(err))\n+\t\t\t} else {\n+\t\t\t\tqueueNamesL.Lock()\n+\t\t\t\tqueueNames = names\n+\t\t\t\tqueueNamesL.Unlock()\n+\t\t\t}\n+\t\t\t<-tick\n+\t\t}\n+\t}()\n+\n+\tfor i := 0; i < srcPoolSize; i++ {\n+\t\tgo forwarder(i)\n+\t}\n+\n+\tselect {}\n+}\n+\n+func forwarder(i int) {\n+\tkv := llog.KV{\"i\": i}\n+\tllog.Info(\"starting forwarder\", kv)\n+\tfn := func(e okq.Event) bool {\n+\t\tif err := dst.PushEvent(e, okq.Normal); err != nil {\n+\t\t\tekv := llog.KV{\"id\": e.ID, \"queue\": e.Queue}\n+\t\t\tllog.Warn(\"error forwarding event\", kv, ekv, llog.ErrKV(err))\n+\t\t\treturn false\n+\t\t}\n+\t\treturn true\n+\t}\n+\n+\ttick := time.Tick(5 * time.Second)\n+outer:\n+\tfor {\n+\t\tqueueNamesL.RLock()\n+\t\tnames := queueNames\n+\t\tqueueNamesL.RUnlock()\n+\t\tif len(names) == 0 {\n+\t\t\t<-tick\n+\t\t\tcontinue\n+\t\t}\n+\n+\t\tstopCh := make(chan bool)\n+\t\terrCh := src.Consumer(fn, stopCh, names...)\n+\n+\t\tfor {\n+\t\t\tselect {\n+\t\t\tcase <-tick:\n+\t\t\t\tif queueNamesChanged(names) {","path":"okq-fwd/main.go","position":169,"original_position":169,"commit_id":"70576ae053517dde0833b25efa94bff397df5a45","original_commit_id":"70576ae053517dde0833b25efa94bff397df5a45","user":{"login":"fastest963","id":112555,"avatar_url":"https://avatars.githubusercontent.com/u/112555?v=3","gravatar_id":"","url":"https://api.github.com/users/fastest963","html_url":"https://github.com/fastest963","followers_url":"https://api.github.com/users/fastest963/followers","following_url":"https://api.github.com/users/fastest963/following{/other_user}","gists_url":"https://api.github.com/users/fastest963/gists{/gist_id}","starred_url":"https://api.github.com/users/fastest963/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fastest963/subscriptions","organizations_url":"https://api.github.com/users/fastest963/orgs","repos_url":"https://api.github.com/users/fastest963/repos","events_url":"https://api.github.com/users/fastest963/events{/privacy}","received_events_url":"https://api.github.com/users/fastest963/received_events","type":"User","site_admin":false},"body":"can this just accept the old and new and compare them?","created_at":"2016-08-16T18:14:51Z","updated_at":"2016-08-16T18:14:51Z","html_url":"https://github.com/levenlabs/goutil/pull/6#discussion_r74990082","pull_request_url":"https://api.github.com/repos/levenlabs/goutil/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/levenlabs/goutil/pulls/comments/74990082"},"html":{"href":"https://github.com/levenlabs/goutil/pull/6#discussion_r74990082"},"pull_request":{"href":"https://api.github.com/repos/levenlabs/goutil/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/levenlabs/goutil/pulls/6","id":81515505,"html_url":"https://github.com/levenlabs/goutil/pull/6","diff_url":"https://github.com/levenlabs/goutil/pull/6.diff","patch_url":"https://github.com/levenlabs/goutil/pull/6.patch","issue_url":"https://api.github.com/repos/levenlabs/goutil/issues/6","number":6,"state":"open","locked":false,"title":"implement okq-fwd","user":{"login":"mediocregopher","id":933154,"avatar_url":"https://avatars.githubusercontent.com/u/933154?v=3","gravatar_id":"","url":"https://api.github.com/users/mediocregopher","html_url":"https://github.com/mediocregopher","followers_url":"https://api.github.com/users/mediocregopher/followers","following_url":"https://api.github.com/users/mediocregopher/following{/other_user}","gists_url":"https://api.github.com/users/mediocregopher/gists{/gist_id}","starred_url":"https://api.github.com/users/mediocregopher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mediocregopher/subscriptions","organizations_url":"https://api.github.com/users/mediocregopher/orgs","repos_url":"https://api.github.com/users/mediocregopher/repos","events_url":"https://api.github.com/users/mediocregopher/events{/privacy}","received_events_url":"https://api.github.com/users/mediocregopher/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-16T17:53:45Z","updated_at":"2016-08-16T18:14:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"39d871fc5f5f4163083bca8f6d4c69e0e45874d3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/levenlabs/goutil/pulls/6/commits","review_comments_url":"https://api.github.com/repos/levenlabs/goutil/pulls/6/comments","review_comment_url":"https://api.github.com/repos/levenlabs/goutil/pulls/comments{/number}","comments_url":"https://api.github.com/repos/levenlabs/goutil/issues/6/comments","statuses_url":"https://api.github.com/repos/levenlabs/goutil/statuses/70576ae053517dde0833b25efa94bff397df5a45","head":{"label":"levenlabs:okq-fwd","ref":"okq-fwd","sha":"70576ae053517dde0833b25efa94bff397df5a45","user":{"login":"levenlabs","id":13338552,"avatar_url":"https://avatars.githubusercontent.com/u/13338552?v=3","gravatar_id":"","url":"https://api.github.com/users/levenlabs","html_url":"https://github.com/levenlabs","followers_url":"https://api.github.com/users/levenlabs/followers","following_url":"https://api.github.com/users/levenlabs/following{/other_user}","gists_url":"https://api.github.com/users/levenlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/levenlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/levenlabs/subscriptions","organizations_url":"https://api.github.com/users/levenlabs/orgs","repos_url":"https://api.github.com/users/levenlabs/repos","events_url":"https://api.github.com/users/levenlabs/events{/privacy}","received_events_url":"https://api.github.com/users/levenlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":46011950,"name":"goutil","full_name":"levenlabs/goutil","owner":{"login":"levenlabs","id":13338552,"avatar_url":"https://avatars.githubusercontent.com/u/13338552?v=3","gravatar_id":"","url":"https://api.github.com/users/levenlabs","html_url":"https://github.com/levenlabs","followers_url":"https://api.github.com/users/levenlabs/followers","following_url":"https://api.github.com/users/levenlabs/following{/other_user}","gists_url":"https://api.github.com/users/levenlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/levenlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/levenlabs/subscriptions","organizations_url":"https://api.github.com/users/levenlabs/orgs","repos_url":"https://api.github.com/users/levenlabs/repos","events_url":"https://api.github.com/users/levenlabs/events{/privacy}","received_events_url":"https://api.github.com/users/levenlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/levenlabs/goutil","description":"When we write a small utility program in go, where it wouldn't make sense to give it its own package, it gets put here","fork":false,"url":"https://api.github.com/repos/levenlabs/goutil","forks_url":"https://api.github.com/repos/levenlabs/goutil/forks","keys_url":"https://api.github.com/repos/levenlabs/goutil/keys{/key_id}","collaborators_url":"https://api.github.com/repos/levenlabs/goutil/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/levenlabs/goutil/teams","hooks_url":"https://api.github.com/repos/levenlabs/goutil/hooks","issue_events_url":"https://api.github.com/repos/levenlabs/goutil/issues/events{/number}","events_url":"https://api.github.com/repos/levenlabs/goutil/events","assignees_url":"https://api.github.com/repos/levenlabs/goutil/assignees{/user}","branches_url":"https://api.github.com/repos/levenlabs/goutil/branches{/branch}","tags_url":"https://api.github.com/repos/levenlabs/goutil/tags","blobs_url":"https://api.github.com/repos/levenlabs/goutil/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/levenlabs/goutil/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/levenlabs/goutil/git/refs{/sha}","trees_url":"https://api.github.com/repos/levenlabs/goutil/git/trees{/sha}","statuses_url":"https://api.github.com/repos/levenlabs/goutil/statuses/{sha}","languages_url":"https://api.github.com/repos/levenlabs/goutil/languages","stargazers_url":"https://api.github.com/repos/levenlabs/goutil/stargazers","contributors_url":"https://api.github.com/repos/levenlabs/goutil/contributors","subscribers_url":"https://api.github.com/repos/levenlabs/goutil/subscribers","subscription_url":"https://api.github.com/repos/levenlabs/goutil/subscription","commits_url":"https://api.github.com/repos/levenlabs/goutil/commits{/sha}","git_commits_url":"https://api.github.com/repos/levenlabs/goutil/git/commits{/sha}","comments_url":"https://api.github.com/repos/levenlabs/goutil/comments{/number}","issue_comment_url":"https://api.github.com/repos/levenlabs/goutil/issues/comments{/number}","contents_url":"https://api.github.com/repos/levenlabs/goutil/contents/{+path}","compare_url":"https://api.github.com/repos/levenlabs/goutil/compare/{base}...{head}","merges_url":"https://api.github.com/repos/levenlabs/goutil/merges","archive_url":"https://api.github.com/repos/levenlabs/goutil/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/levenlabs/goutil/downloads","issues_url":"https://api.github.com/repos/levenlabs/goutil/issues{/number}","pulls_url":"https://api.github.com/repos/levenlabs/goutil/pulls{/number}","milestones_url":"https://api.github.com/repos/levenlabs/goutil/milestones{/number}","notifications_url":"https://api.github.com/repos/levenlabs/goutil/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/levenlabs/goutil/labels{/name}","releases_url":"https://api.github.com/repos/levenlabs/goutil/releases{/id}","deployments_url":"https://api.github.com/repos/levenlabs/goutil/deployments","created_at":"2015-11-11T21:48:43Z","updated_at":"2016-02-10T23:00:09Z","pushed_at":"2016-08-16T17:53:45Z","git_url":"git://github.com/levenlabs/goutil.git","ssh_url":"git@github.com:levenlabs/goutil.git","clone_url":"https://github.com/levenlabs/goutil.git","svn_url":"https://github.com/levenlabs/goutil","homepage":null,"size":7,"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":"levenlabs:master","ref":"master","sha":"24d289f90535ec71bf731802eaf5900c3e668a81","user":{"login":"levenlabs","id":13338552,"avatar_url":"https://avatars.githubusercontent.com/u/13338552?v=3","gravatar_id":"","url":"https://api.github.com/users/levenlabs","html_url":"https://github.com/levenlabs","followers_url":"https://api.github.com/users/levenlabs/followers","following_url":"https://api.github.com/users/levenlabs/following{/other_user}","gists_url":"https://api.github.com/users/levenlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/levenlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/levenlabs/subscriptions","organizations_url":"https://api.github.com/users/levenlabs/orgs","repos_url":"https://api.github.com/users/levenlabs/repos","events_url":"https://api.github.com/users/levenlabs/events{/privacy}","received_events_url":"https://api.github.com/users/levenlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":46011950,"name":"goutil","full_name":"levenlabs/goutil","owner":{"login":"levenlabs","id":13338552,"avatar_url":"https://avatars.githubusercontent.com/u/13338552?v=3","gravatar_id":"","url":"https://api.github.com/users/levenlabs","html_url":"https://github.com/levenlabs","followers_url":"https://api.github.com/users/levenlabs/followers","following_url":"https://api.github.com/users/levenlabs/following{/other_user}","gists_url":"https://api.github.com/users/levenlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/levenlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/levenlabs/subscriptions","organizations_url":"https://api.github.com/users/levenlabs/orgs","repos_url":"https://api.github.com/users/levenlabs/repos","events_url":"https://api.github.com/users/levenlabs/events{/privacy}","received_events_url":"https://api.github.com/users/levenlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/levenlabs/goutil","description":"When we write a small utility program in go, where it wouldn't make sense to give it its own package, it gets put here","fork":false,"url":"https://api.github.com/repos/levenlabs/goutil","forks_url":"https://api.github.com/repos/levenlabs/goutil/forks","keys_url":"https://api.github.com/repos/levenlabs/goutil/keys{/key_id}","collaborators_url":"https://api.github.com/repos/levenlabs/goutil/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/levenlabs/goutil/teams","hooks_url":"https://api.github.com/repos/levenlabs/goutil/hooks","issue_events_url":"https://api.github.com/repos/levenlabs/goutil/issues/events{/number}","events_url":"https://api.github.com/repos/levenlabs/goutil/events","assignees_url":"https://api.github.com/repos/levenlabs/goutil/assignees{/user}","branches_url":"https://api.github.com/repos/levenlabs/goutil/branches{/branch}","tags_url":"https://api.github.com/repos/levenlabs/goutil/tags","blobs_url":"https://api.github.com/repos/levenlabs/goutil/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/levenlabs/goutil/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/levenlabs/goutil/git/refs{/sha}","trees_url":"https://api.github.com/repos/levenlabs/goutil/git/trees{/sha}","statuses_url":"https://api.github.com/repos/levenlabs/goutil/statuses/{sha}","languages_url":"https://api.github.com/repos/levenlabs/goutil/languages","stargazers_url":"https://api.github.com/repos/levenlabs/goutil/stargazers","contributors_url":"https://api.github.com/repos/levenlabs/goutil/contributors","subscribers_url":"https://api.github.com/repos/levenlabs/goutil/subscribers","subscription_url":"https://api.github.com/repos/levenlabs/goutil/subscription","commits_url":"https://api.github.com/repos/levenlabs/goutil/commits{/sha}","git_commits_url":"https://api.github.com/repos/levenlabs/goutil/git/commits{/sha}","comments_url":"https://api.github.com/repos/levenlabs/goutil/comments{/number}","issue_comment_url":"https://api.github.com/repos/levenlabs/goutil/issues/comments{/number}","contents_url":"https://api.github.com/repos/levenlabs/goutil/contents/{+path}","compare_url":"https://api.github.com/repos/levenlabs/goutil/compare/{base}...{head}","merges_url":"https://api.github.com/repos/levenlabs/goutil/merges","archive_url":"https://api.github.com/repos/levenlabs/goutil/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/levenlabs/goutil/downloads","issues_url":"https://api.github.com/repos/levenlabs/goutil/issues{/number}","pulls_url":"https://api.github.com/repos/levenlabs/goutil/pulls{/number}","milestones_url":"https://api.github.com/repos/levenlabs/goutil/milestones{/number}","notifications_url":"https://api.github.com/repos/levenlabs/goutil/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/levenlabs/goutil/labels{/name}","releases_url":"https://api.github.com/repos/levenlabs/goutil/releases{/id}","deployments_url":"https://api.github.com/repos/levenlabs/goutil/deployments","created_at":"2015-11-11T21:48:43Z","updated_at":"2016-02-10T23:00:09Z","pushed_at":"2016-08-16T17:53:45Z","git_url":"git://github.com/levenlabs/goutil.git","ssh_url":"git@github.com:levenlabs/goutil.git","clone_url":"https://github.com/levenlabs/goutil.git","svn_url":"https://github.com/levenlabs/goutil","homepage":null,"size":7,"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/levenlabs/goutil/pulls/6"},"html":{"href":"https://github.com/levenlabs/goutil/pull/6"},"issue":{"href":"https://api.github.com/repos/levenlabs/goutil/issues/6"},"comments":{"href":"https://api.github.com/repos/levenlabs/goutil/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/levenlabs/goutil/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/levenlabs/goutil/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/levenlabs/goutil/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/levenlabs/goutil/statuses/70576ae053517dde0833b25efa94bff397df5a45"}}}}
{"actor":{"display_login":"fastest963"}}