{"action":"created","comment":{"url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/comments/23796240","id":23796240,"diff_hunk":"@@ -20,26 +22,44 @@ func lineWorker(die dieCh, r *bufio.Reader, cfg logplexc.Config, sr *serveRecord\n \t\tlog.Fatalf(\"could not create logging client: %v\", err)\n \t}\n \n-\tfor {\n-\t\tselect {\n-\t\tcase <-die:\n-\t\t\treturn\n-\t\tdefault:\n-\t\t\tbreak\n-\t\t}\n+\twatcher, err := fsnotify.NewWatcher()\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\tdefer watcher.Close()\n \n-\t\tl, _, err := r.ReadLine()\n-\t\tl = prefix.ReplaceAll(l, []byte(\"\"))\n-\t\tif len(l) > 0 {\n-\t\t\ttarget.BufferMessage(134, time.Now(), \"redis\",\n-\t\t\t\tsr.Name, l)\n-\t\t}\n+\tr := bufio.NewReader(f)\n \n-\t\tif err != nil {\n-\t\t\tif err == io.EOF {\n-\t\t\t\tcontinue\n+\tgo func() {\n+\t\tfor {\n+\t\t\tselect {\n+\t\t\tcase event := <-watcher.Events:\n+\t\t\t\tif event.Op&fsnotify.Write == fsnotify.Write {","path":"logfile.go","position":51,"original_position":51,"commit_id":"653a2fb4578a14796faf5948d6c15638b272fc45","original_commit_id":"653a2fb4578a14796faf5948d6c15638b272fc45","user":{"login":"cyberdelia","id":44535,"avatar_url":"https://avatars.githubusercontent.com/u/44535?v=3","gravatar_id":"","url":"https://api.github.com/users/cyberdelia","html_url":"https://github.com/cyberdelia","followers_url":"https://api.github.com/users/cyberdelia/followers","following_url":"https://api.github.com/users/cyberdelia/following{/other_user}","gists_url":"https://api.github.com/users/cyberdelia/gists{/gist_id}","starred_url":"https://api.github.com/users/cyberdelia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyberdelia/subscriptions","organizations_url":"https://api.github.com/users/cyberdelia/orgs","repos_url":"https://api.github.com/users/cyberdelia/repos","events_url":"https://api.github.com/users/cyberdelia/events{/privacy}","received_events_url":"https://api.github.com/users/cyberdelia/received_events","type":"User","site_admin":false},"body":"``fsnotify`` is not ``inotify`` only, so it's actually fairly portable. A ``time.Sleep`` fallback could do the trick anyway.","created_at":"2015-01-29T19:41:21Z","updated_at":"2015-01-29T19:41:21Z","html_url":"https://github.com/heroku/pg_logplexcollector/pull/2#discussion_r23796240","pull_request_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/comments/23796240"},"html":{"href":"https://github.com/heroku/pg_logplexcollector/pull/2#discussion_r23796240"},"pull_request":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2","id":28067791,"html_url":"https://github.com/heroku/pg_logplexcollector/pull/2","diff_url":"https://github.com/heroku/pg_logplexcollector/pull/2.diff","patch_url":"https://github.com/heroku/pg_logplexcollector/pull/2.patch","issue_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/2","number":2,"state":"closed","locked":false,"title":"Avoid expensive polling","user":{"login":"cyberdelia","id":44535,"avatar_url":"https://avatars.githubusercontent.com/u/44535?v=3","gravatar_id":"","url":"https://api.github.com/users/cyberdelia","html_url":"https://github.com/cyberdelia","followers_url":"https://api.github.com/users/cyberdelia/followers","following_url":"https://api.github.com/users/cyberdelia/following{/other_user}","gists_url":"https://api.github.com/users/cyberdelia/gists{/gist_id}","starred_url":"https://api.github.com/users/cyberdelia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cyberdelia/subscriptions","organizations_url":"https://api.github.com/users/cyberdelia/orgs","repos_url":"https://api.github.com/users/cyberdelia/repos","events_url":"https://api.github.com/users/cyberdelia/events{/privacy}","received_events_url":"https://api.github.com/users/cyberdelia/received_events","type":"User","site_admin":false},"body":"This avoid using too much resources when the file/fifo is closed for writing.","created_at":"2015-01-26T22:51:08Z","updated_at":"2015-01-29T19:41:21Z","closed_at":"2015-01-29T00:30:39Z","merged_at":"2015-01-29T00:30:39Z","merge_commit_sha":"c028a924e258bff8e9055d846e0b5628aa1e9788","assignee":{"login":"fdr","id":7191,"avatar_url":"https://avatars.githubusercontent.com/u/7191?v=3","gravatar_id":"","url":"https://api.github.com/users/fdr","html_url":"https://github.com/fdr","followers_url":"https://api.github.com/users/fdr/followers","following_url":"https://api.github.com/users/fdr/following{/other_user}","gists_url":"https://api.github.com/users/fdr/gists{/gist_id}","starred_url":"https://api.github.com/users/fdr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fdr/subscriptions","organizations_url":"https://api.github.com/users/fdr/orgs","repos_url":"https://api.github.com/users/fdr/repos","events_url":"https://api.github.com/users/fdr/events{/privacy}","received_events_url":"https://api.github.com/users/fdr/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2/commits","review_comments_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2/comments","review_comment_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/comments/{number}","comments_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/2/comments","statuses_url":"https://api.github.com/repos/heroku/pg_logplexcollector/statuses/653a2fb4578a14796faf5948d6c15638b272fc45","head":{"label":"heroku:fsnotify","ref":"fsnotify","sha":"653a2fb4578a14796faf5948d6c15638b272fc45","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":9212385,"name":"pg_logplexcollector","full_name":"heroku/pg_logplexcollector","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/pg_logplexcollector","description":"Collect logs from Postgres servers and send to Logplex","fork":true,"url":"https://api.github.com/repos/heroku/pg_logplexcollector","forks_url":"https://api.github.com/repos/heroku/pg_logplexcollector/forks","keys_url":"https://api.github.com/repos/heroku/pg_logplexcollector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/pg_logplexcollector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/pg_logplexcollector/teams","hooks_url":"https://api.github.com/repos/heroku/pg_logplexcollector/hooks","issue_events_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/pg_logplexcollector/events","assignees_url":"https://api.github.com/repos/heroku/pg_logplexcollector/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/pg_logplexcollector/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/pg_logplexcollector/tags","blobs_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/pg_logplexcollector/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/pg_logplexcollector/languages","stargazers_url":"https://api.github.com/repos/heroku/pg_logplexcollector/stargazers","contributors_url":"https://api.github.com/repos/heroku/pg_logplexcollector/contributors","subscribers_url":"https://api.github.com/repos/heroku/pg_logplexcollector/subscribers","subscription_url":"https://api.github.com/repos/heroku/pg_logplexcollector/subscription","commits_url":"https://api.github.com/repos/heroku/pg_logplexcollector/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/pg_logplexcollector/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/comments/{number}","contents_url":"https://api.github.com/repos/heroku/pg_logplexcollector/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/pg_logplexcollector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/pg_logplexcollector/merges","archive_url":"https://api.github.com/repos/heroku/pg_logplexcollector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/pg_logplexcollector/downloads","issues_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/pg_logplexcollector/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/pg_logplexcollector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/pg_logplexcollector/labels{/name}","releases_url":"https://api.github.com/repos/heroku/pg_logplexcollector/releases{/id}","created_at":"2013-04-04T06:26:01Z","updated_at":"2015-01-29T01:15:46Z","pushed_at":"2015-01-29T01:15:46Z","git_url":"git://github.com/heroku/pg_logplexcollector.git","ssh_url":"git@github.com:heroku/pg_logplexcollector.git","clone_url":"https://github.com/heroku/pg_logplexcollector.git","svn_url":"https://github.com/heroku/pg_logplexcollector","homepage":null,"size":417,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"heroku:master","ref":"master","sha":"1120a0fa8ff903bfc75af73b793b94f27d458e52","user":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"repo":{"id":9212385,"name":"pg_logplexcollector","full_name":"heroku/pg_logplexcollector","owner":{"login":"heroku","id":23211,"avatar_url":"https://avatars.githubusercontent.com/u/23211?v=3","gravatar_id":"","url":"https://api.github.com/users/heroku","html_url":"https://github.com/heroku","followers_url":"https://api.github.com/users/heroku/followers","following_url":"https://api.github.com/users/heroku/following{/other_user}","gists_url":"https://api.github.com/users/heroku/gists{/gist_id}","starred_url":"https://api.github.com/users/heroku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heroku/subscriptions","organizations_url":"https://api.github.com/users/heroku/orgs","repos_url":"https://api.github.com/users/heroku/repos","events_url":"https://api.github.com/users/heroku/events{/privacy}","received_events_url":"https://api.github.com/users/heroku/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/heroku/pg_logplexcollector","description":"Collect logs from Postgres servers and send to Logplex","fork":true,"url":"https://api.github.com/repos/heroku/pg_logplexcollector","forks_url":"https://api.github.com/repos/heroku/pg_logplexcollector/forks","keys_url":"https://api.github.com/repos/heroku/pg_logplexcollector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/heroku/pg_logplexcollector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/heroku/pg_logplexcollector/teams","hooks_url":"https://api.github.com/repos/heroku/pg_logplexcollector/hooks","issue_events_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/events{/number}","events_url":"https://api.github.com/repos/heroku/pg_logplexcollector/events","assignees_url":"https://api.github.com/repos/heroku/pg_logplexcollector/assignees{/user}","branches_url":"https://api.github.com/repos/heroku/pg_logplexcollector/branches{/branch}","tags_url":"https://api.github.com/repos/heroku/pg_logplexcollector/tags","blobs_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/refs{/sha}","trees_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/heroku/pg_logplexcollector/statuses/{sha}","languages_url":"https://api.github.com/repos/heroku/pg_logplexcollector/languages","stargazers_url":"https://api.github.com/repos/heroku/pg_logplexcollector/stargazers","contributors_url":"https://api.github.com/repos/heroku/pg_logplexcollector/contributors","subscribers_url":"https://api.github.com/repos/heroku/pg_logplexcollector/subscribers","subscription_url":"https://api.github.com/repos/heroku/pg_logplexcollector/subscription","commits_url":"https://api.github.com/repos/heroku/pg_logplexcollector/commits{/sha}","git_commits_url":"https://api.github.com/repos/heroku/pg_logplexcollector/git/commits{/sha}","comments_url":"https://api.github.com/repos/heroku/pg_logplexcollector/comments{/number}","issue_comment_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/comments/{number}","contents_url":"https://api.github.com/repos/heroku/pg_logplexcollector/contents/{+path}","compare_url":"https://api.github.com/repos/heroku/pg_logplexcollector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/heroku/pg_logplexcollector/merges","archive_url":"https://api.github.com/repos/heroku/pg_logplexcollector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/heroku/pg_logplexcollector/downloads","issues_url":"https://api.github.com/repos/heroku/pg_logplexcollector/issues{/number}","pulls_url":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls{/number}","milestones_url":"https://api.github.com/repos/heroku/pg_logplexcollector/milestones{/number}","notifications_url":"https://api.github.com/repos/heroku/pg_logplexcollector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/heroku/pg_logplexcollector/labels{/name}","releases_url":"https://api.github.com/repos/heroku/pg_logplexcollector/releases{/id}","created_at":"2013-04-04T06:26:01Z","updated_at":"2015-01-29T01:15:46Z","pushed_at":"2015-01-29T01:15:46Z","git_url":"git://github.com/heroku/pg_logplexcollector.git","ssh_url":"git@github.com:heroku/pg_logplexcollector.git","clone_url":"https://github.com/heroku/pg_logplexcollector.git","svn_url":"https://github.com/heroku/pg_logplexcollector","homepage":null,"size":417,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2"},"html":{"href":"https://github.com/heroku/pg_logplexcollector/pull/2"},"issue":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/2"},"comments":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/heroku/pg_logplexcollector/statuses/653a2fb4578a14796faf5948d6c15638b272fc45"}}}}