{"action":"created","comment":{"url":"https://api.github.com/repos/os-autoinst/openQA/pulls/comments/25790565","id":25790565,"diff_hunk":"@@ -138,43 +145,83 @@ sub api_init {\n     }\n }\n \n+my $call_running;\n # send a command to openQA API\n sub api_call {\n     my ($method, $path, $params, $json_data, $ignore_errors) = @_;\n-    $method = lc $method;\n+\n+    return undef unless verify_workerid();\n+    if ($call_running) {\n+        print \"api call in progress, not accepting new one\\n\" if $verbose;\n+        return undef;\n+    }\n+\n+    $call_running = 1;\n+\n+    $method = uc $method;\n     my $ua_url = $url->clone;\n \n     $ua_url->path($path =~ s/^\\///r);\n     $ua_url->query($params) if $params;\n \n-    my $tries = 3;\n-    while (1) {\n-        print uc($method) . \" $ua_url\\n\" if $verbose;\n-        my $tx;\n-        if ($json_data) {\n-            $tx = $ua->$method($ua_url => json => $json_data);\n-        }\n-        else {\n-            $tx = $ua->$method($ua_url);\n-        }\n+    print $method . \" $ua_url\\n\" if $verbose;\n+\n+    my @args = ($method, $ua_url);\n+\n+    if ($json_data) {\n+        push @args, 'json', $json_data;\n+    }\n+\n+    my $res;\n+    my $done = 0;\n+\n+    my $tx = $ua->build_tx(@args);\n+    my $cb;\n+    $cb = sub {\n+        my ($ua, $tx, $tries) = @_;\n+        remove_timer('api_call');\n         if ($tx->success) {\n-            return $tx->success->json;\n+            $res = $tx->success->json;\n+            $done = 1;\n+            return;\n         }\n         elsif ($ignore_errors) {\n+            $done = 1;\n             return;\n         }\n         --$tries;\n-        my ($err, $code) = $tx->error;\n-        my $msg = $code ? \"$tries: $code response: $err\" : \"$tries: Connection error: $err->{message}\";\n-        carp \"$msg\";\n+        my $err = $tx->error;\n+        my $msg = $err->{code} ? \"$tries: $err->{code} response: $err->{message}\" : \"$tries: Connection error: $err->{message}\";\n+        warn $msg;\n         if (!$tries) {\n             # abort the current job, we're in trouble - but keep running to grab the next\n-            # this lives in Jobs.pm - this is recursive use?\n-            #stop_job('api-failure');\n+            remove_timer('setup_websocket');\n+            $workerid = undef;\n+            OpenQA::Worker::Jobs::stop_job('api-failure');\n+            add_timer('register_worker', 10, \\&register_worker, 1);\n+            $done = 1;\n             return;\n         }\n-        sleep 5;\n+        $tx = $ua->build_tx(@args);\n+        add_timer(\n+            'api_call',\n+            5,\n+            sub {\n+                $ua->start($tx => sub { $cb->(@_, $tries) });\n+            },\n+            1\n+        );\n+    };\n+    $ua->start($tx => sub { $cb->(@_, 3) });\n+\n+    # This ugly. we need to \"block\" here so enter ioloop recursively\n+    while(!$done && Mojo::IOLoop->is_running) {","path":"lib/OpenQA/Worker/Common.pm","position":133,"original_position":133,"commit_id":"811995bbcea3cc7e82a47e546b2e06bca50328f7","original_commit_id":"811995bbcea3cc7e82a47e546b2e06bca50328f7","user":{"login":"coolo","id":1067203,"avatar_url":"https://avatars.githubusercontent.com/u/1067203?v=3","gravatar_id":"","url":"https://api.github.com/users/coolo","html_url":"https://github.com/coolo","followers_url":"https://api.github.com/users/coolo/followers","following_url":"https://api.github.com/users/coolo/following{/other_user}","gists_url":"https://api.github.com/users/coolo/gists{/gist_id}","starred_url":"https://api.github.com/users/coolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coolo/subscriptions","organizations_url":"https://api.github.com/users/coolo/orgs","repos_url":"https://api.github.com/users/coolo/repos","events_url":"https://api.github.com/users/coolo/events{/privacy}","received_events_url":"https://api.github.com/users/coolo/received_events","type":"User","site_admin":false},"body":"it still has to block - all places calling expect the call to be done when it returns","created_at":"2015-03-04T16:53:10Z","updated_at":"2015-03-04T16:53:10Z","html_url":"https://github.com/os-autoinst/openQA/pull/219#discussion_r25790565","pull_request_url":"https://api.github.com/repos/os-autoinst/openQA/pulls/219","_links":{"self":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/comments/25790565"},"html":{"href":"https://github.com/os-autoinst/openQA/pull/219#discussion_r25790565"},"pull_request":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/219"}}},"pull_request":{"url":"https://api.github.com/repos/os-autoinst/openQA/pulls/219","id":30465378,"html_url":"https://github.com/os-autoinst/openQA/pull/219","diff_url":"https://github.com/os-autoinst/openQA/pull/219.diff","patch_url":"https://github.com/os-autoinst/openQA/pull/219.patch","issue_url":"https://api.github.com/repos/os-autoinst/openQA/issues/219","number":219,"state":"open","locked":false,"title":"worker websocket improvements","user":{"login":"lnussel","id":722232,"avatar_url":"https://avatars.githubusercontent.com/u/722232?v=3","gravatar_id":"","url":"https://api.github.com/users/lnussel","html_url":"https://github.com/lnussel","followers_url":"https://api.github.com/users/lnussel/followers","following_url":"https://api.github.com/users/lnussel/following{/other_user}","gists_url":"https://api.github.com/users/lnussel/gists{/gist_id}","starred_url":"https://api.github.com/users/lnussel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnussel/subscriptions","organizations_url":"https://api.github.com/users/lnussel/orgs","repos_url":"https://api.github.com/users/lnussel/repos","events_url":"https://api.github.com/users/lnussel/events{/privacy}","received_events_url":"https://api.github.com/users/lnussel/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-04T13:38:52Z","updated_at":"2015-03-04T16:53:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"46597104454709f93adef748042ad4d22e58a39b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/os-autoinst/openQA/pulls/219/commits","review_comments_url":"https://api.github.com/repos/os-autoinst/openQA/pulls/219/comments","review_comment_url":"https://api.github.com/repos/os-autoinst/openQA/pulls/comments{/number}","comments_url":"https://api.github.com/repos/os-autoinst/openQA/issues/219/comments","statuses_url":"https://api.github.com/repos/os-autoinst/openQA/statuses/811995bbcea3cc7e82a47e546b2e06bca50328f7","head":{"label":"lnussel:websocket","ref":"websocket","sha":"811995bbcea3cc7e82a47e546b2e06bca50328f7","user":{"login":"lnussel","id":722232,"avatar_url":"https://avatars.githubusercontent.com/u/722232?v=3","gravatar_id":"","url":"https://api.github.com/users/lnussel","html_url":"https://github.com/lnussel","followers_url":"https://api.github.com/users/lnussel/followers","following_url":"https://api.github.com/users/lnussel/following{/other_user}","gists_url":"https://api.github.com/users/lnussel/gists{/gist_id}","starred_url":"https://api.github.com/users/lnussel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnussel/subscriptions","organizations_url":"https://api.github.com/users/lnussel/orgs","repos_url":"https://api.github.com/users/lnussel/repos","events_url":"https://api.github.com/users/lnussel/events{/privacy}","received_events_url":"https://api.github.com/users/lnussel/received_events","type":"User","site_admin":false},"repo":{"id":20884105,"name":"openQA","full_name":"lnussel/openQA","owner":{"login":"lnussel","id":722232,"avatar_url":"https://avatars.githubusercontent.com/u/722232?v=3","gravatar_id":"","url":"https://api.github.com/users/lnussel","html_url":"https://github.com/lnussel","followers_url":"https://api.github.com/users/lnussel/followers","following_url":"https://api.github.com/users/lnussel/following{/other_user}","gists_url":"https://api.github.com/users/lnussel/gists{/gist_id}","starred_url":"https://api.github.com/users/lnussel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lnussel/subscriptions","organizations_url":"https://api.github.com/users/lnussel/orgs","repos_url":"https://api.github.com/users/lnussel/repos","events_url":"https://api.github.com/users/lnussel/events{/privacy}","received_events_url":"https://api.github.com/users/lnussel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lnussel/openQA","description":"","fork":true,"url":"https://api.github.com/repos/lnussel/openQA","forks_url":"https://api.github.com/repos/lnussel/openQA/forks","keys_url":"https://api.github.com/repos/lnussel/openQA/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lnussel/openQA/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lnussel/openQA/teams","hooks_url":"https://api.github.com/repos/lnussel/openQA/hooks","issue_events_url":"https://api.github.com/repos/lnussel/openQA/issues/events{/number}","events_url":"https://api.github.com/repos/lnussel/openQA/events","assignees_url":"https://api.github.com/repos/lnussel/openQA/assignees{/user}","branches_url":"https://api.github.com/repos/lnussel/openQA/branches{/branch}","tags_url":"https://api.github.com/repos/lnussel/openQA/tags","blobs_url":"https://api.github.com/repos/lnussel/openQA/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lnussel/openQA/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lnussel/openQA/git/refs{/sha}","trees_url":"https://api.github.com/repos/lnussel/openQA/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lnussel/openQA/statuses/{sha}","languages_url":"https://api.github.com/repos/lnussel/openQA/languages","stargazers_url":"https://api.github.com/repos/lnussel/openQA/stargazers","contributors_url":"https://api.github.com/repos/lnussel/openQA/contributors","subscribers_url":"https://api.github.com/repos/lnussel/openQA/subscribers","subscription_url":"https://api.github.com/repos/lnussel/openQA/subscription","commits_url":"https://api.github.com/repos/lnussel/openQA/commits{/sha}","git_commits_url":"https://api.github.com/repos/lnussel/openQA/git/commits{/sha}","comments_url":"https://api.github.com/repos/lnussel/openQA/comments{/number}","issue_comment_url":"https://api.github.com/repos/lnussel/openQA/issues/comments{/number}","contents_url":"https://api.github.com/repos/lnussel/openQA/contents/{+path}","compare_url":"https://api.github.com/repos/lnussel/openQA/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lnussel/openQA/merges","archive_url":"https://api.github.com/repos/lnussel/openQA/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lnussel/openQA/downloads","issues_url":"https://api.github.com/repos/lnussel/openQA/issues{/number}","pulls_url":"https://api.github.com/repos/lnussel/openQA/pulls{/number}","milestones_url":"https://api.github.com/repos/lnussel/openQA/milestones{/number}","notifications_url":"https://api.github.com/repos/lnussel/openQA/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lnussel/openQA/labels{/name}","releases_url":"https://api.github.com/repos/lnussel/openQA/releases{/id}","created_at":"2014-06-16T12:32:30Z","updated_at":"2015-02-27T12:22:13Z","pushed_at":"2015-03-04T16:01:21Z","git_url":"git://github.com/lnussel/openQA.git","ssh_url":"git@github.com:lnussel/openQA.git","clone_url":"https://github.com/lnussel/openQA.git","svn_url":"https://github.com/lnussel/openQA","homepage":null,"size":13023,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"os-autoinst:master","ref":"master","sha":"bb9bcbe49029a643c72b9ade2d4a89c48dc63d71","user":{"login":"os-autoinst","id":6918706,"avatar_url":"https://avatars.githubusercontent.com/u/6918706?v=3","gravatar_id":"","url":"https://api.github.com/users/os-autoinst","html_url":"https://github.com/os-autoinst","followers_url":"https://api.github.com/users/os-autoinst/followers","following_url":"https://api.github.com/users/os-autoinst/following{/other_user}","gists_url":"https://api.github.com/users/os-autoinst/gists{/gist_id}","starred_url":"https://api.github.com/users/os-autoinst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/os-autoinst/subscriptions","organizations_url":"https://api.github.com/users/os-autoinst/orgs","repos_url":"https://api.github.com/users/os-autoinst/repos","events_url":"https://api.github.com/users/os-autoinst/events{/privacy}","received_events_url":"https://api.github.com/users/os-autoinst/received_events","type":"Organization","site_admin":false},"repo":{"id":20883829,"name":"openQA","full_name":"os-autoinst/openQA","owner":{"login":"os-autoinst","id":6918706,"avatar_url":"https://avatars.githubusercontent.com/u/6918706?v=3","gravatar_id":"","url":"https://api.github.com/users/os-autoinst","html_url":"https://github.com/os-autoinst","followers_url":"https://api.github.com/users/os-autoinst/followers","following_url":"https://api.github.com/users/os-autoinst/following{/other_user}","gists_url":"https://api.github.com/users/os-autoinst/gists{/gist_id}","starred_url":"https://api.github.com/users/os-autoinst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/os-autoinst/subscriptions","organizations_url":"https://api.github.com/users/os-autoinst/orgs","repos_url":"https://api.github.com/users/os-autoinst/repos","events_url":"https://api.github.com/users/os-autoinst/events{/privacy}","received_events_url":"https://api.github.com/users/os-autoinst/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/os-autoinst/openQA","description":"openQA web-frontend, scheduler and tools","fork":false,"url":"https://api.github.com/repos/os-autoinst/openQA","forks_url":"https://api.github.com/repos/os-autoinst/openQA/forks","keys_url":"https://api.github.com/repos/os-autoinst/openQA/keys{/key_id}","collaborators_url":"https://api.github.com/repos/os-autoinst/openQA/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/os-autoinst/openQA/teams","hooks_url":"https://api.github.com/repos/os-autoinst/openQA/hooks","issue_events_url":"https://api.github.com/repos/os-autoinst/openQA/issues/events{/number}","events_url":"https://api.github.com/repos/os-autoinst/openQA/events","assignees_url":"https://api.github.com/repos/os-autoinst/openQA/assignees{/user}","branches_url":"https://api.github.com/repos/os-autoinst/openQA/branches{/branch}","tags_url":"https://api.github.com/repos/os-autoinst/openQA/tags","blobs_url":"https://api.github.com/repos/os-autoinst/openQA/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/os-autoinst/openQA/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/os-autoinst/openQA/git/refs{/sha}","trees_url":"https://api.github.com/repos/os-autoinst/openQA/git/trees{/sha}","statuses_url":"https://api.github.com/repos/os-autoinst/openQA/statuses/{sha}","languages_url":"https://api.github.com/repos/os-autoinst/openQA/languages","stargazers_url":"https://api.github.com/repos/os-autoinst/openQA/stargazers","contributors_url":"https://api.github.com/repos/os-autoinst/openQA/contributors","subscribers_url":"https://api.github.com/repos/os-autoinst/openQA/subscribers","subscription_url":"https://api.github.com/repos/os-autoinst/openQA/subscription","commits_url":"https://api.github.com/repos/os-autoinst/openQA/commits{/sha}","git_commits_url":"https://api.github.com/repos/os-autoinst/openQA/git/commits{/sha}","comments_url":"https://api.github.com/repos/os-autoinst/openQA/comments{/number}","issue_comment_url":"https://api.github.com/repos/os-autoinst/openQA/issues/comments{/number}","contents_url":"https://api.github.com/repos/os-autoinst/openQA/contents/{+path}","compare_url":"https://api.github.com/repos/os-autoinst/openQA/compare/{base}...{head}","merges_url":"https://api.github.com/repos/os-autoinst/openQA/merges","archive_url":"https://api.github.com/repos/os-autoinst/openQA/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/os-autoinst/openQA/downloads","issues_url":"https://api.github.com/repos/os-autoinst/openQA/issues{/number}","pulls_url":"https://api.github.com/repos/os-autoinst/openQA/pulls{/number}","milestones_url":"https://api.github.com/repos/os-autoinst/openQA/milestones{/number}","notifications_url":"https://api.github.com/repos/os-autoinst/openQA/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/os-autoinst/openQA/labels{/name}","releases_url":"https://api.github.com/repos/os-autoinst/openQA/releases{/id}","created_at":"2014-06-16T12:23:22Z","updated_at":"2015-03-04T16:44:15Z","pushed_at":"2015-03-04T16:44:15Z","git_url":"git://github.com/os-autoinst/openQA.git","ssh_url":"git@github.com:os-autoinst/openQA.git","clone_url":"https://github.com/os-autoinst/openQA.git","svn_url":"https://github.com/os-autoinst/openQA","homepage":"http://openqa.opensuse.org/","size":15915,"stargazers_count":12,"watchers_count":12,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":18,"mirror_url":null,"open_issues_count":7,"forks":18,"open_issues":7,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/219"},"html":{"href":"https://github.com/os-autoinst/openQA/pull/219"},"issue":{"href":"https://api.github.com/repos/os-autoinst/openQA/issues/219"},"comments":{"href":"https://api.github.com/repos/os-autoinst/openQA/issues/219/comments"},"review_comments":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/219/comments"},"review_comment":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/os-autoinst/openQA/pulls/219/commits"},"statuses":{"href":"https://api.github.com/repos/os-autoinst/openQA/statuses/811995bbcea3cc7e82a47e546b2e06bca50328f7"}}}}