{"id":366,"date":"2018-12-06T11:45:40","date_gmt":"2018-12-06T03:45:40","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=366"},"modified":"2022-05-17T09:44:31","modified_gmt":"2022-05-17T01:44:31","slug":"jira-api","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=366","title":{"rendered":"jira-api\u4f7f\u7528gevent\uff0c\u5feb\u901f\u6279\u91cf\u4fee\u6539\u6570\u636e"},"content":{"rendered":"<h1>\u9700\u6c42<\/h1>\n<p>\u56e0\u4e3a\u6211\u4eec\u672c\u5730\u6570\u636e\u5e93\u4e2d\u7ecf\u5e38\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u9700\u8981\u540c\u6b65\u81f3jira.\u8986\u76d6\u6389jira\u4e0a\u7684\u8001\u6570\u636e\u3002<br \/>\n\u56e0\u4e3ajira\u670d\u52a1\u5668\u90e8\u7f72\u5728\u56fd\u5916\uff0c\u8fde\u63a5\u5de8\u6162\u3002\u6bcf\u6b21\u4fee\u6539\u4e00\u4e2a\uff0c\u81f3\u5c11\u9700\u8981\u82b1\u8d3910\u79d2\u5de6\u53f3\u7684\u65f6\u95f4\u3002<br \/>\n\u800cjira-api\u6ca1\u6709\u63d0\u4f9b\u6279\u91cf\u6216\u8005\u5f02\u6b65\u540c\u6b65\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u9700\u8981\u81ea\u5df1\u4f7f\u7528\u4e00\u4e2a\u5f02\u6b65\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u4e00\u6b21\u6027\u628a\u6240\u6709\u7684\u8bf7\u6c42\u53d1\u9001\u51fa\u53bb\u3002<br \/>\njira\u670d\u52a1\u7aef\u6709\u65f6\u5019\u5403\u4e0d\u6d88\uff0c\u4f1a\u5173\u95ed\u6389\u6211\u7684\u4e00\u4e9b\u8fde\u63a5\uff0c\u6240\u4ee5\u8fd8\u9700\u8981\u5728\u88ab\u5173\u95ed\u4e4b\u540e\uff0c\u8bb0\u5f55\u4e0b\u8fd9\u4e9b\u540c\u6b65\u81f3jira\u5931\u8d25\u7684\uff0c\u91cd\u65b0\u7ee7\u7eed\u4fee\u6539\u64cd\u4f5c<\/p>\n<h1>\u7528\u5230\u7684\u5e93<\/h1>\n<h5><strong><span style=\"color: #000000;\">gevent\u00a0 \u5e93<\/span><\/strong><\/h5>\n<header>\n<blockquote><p>gevent\u662f\u4e00\u4e2a\u57fa\u4e8e<a href=\"http:\/\/software.schmorp.de\/pkg\/libev.html\">libev<\/a>\u7684\u5e76\u53d1\u5e93\u3002\u5b83\u4e3a\u5404\u79cd\u5e76\u53d1\u548c\u7f51\u7edc\u76f8\u5173\u7684\u4efb\u52a1\u63d0\u4f9b\u4e86\u6574\u6d01\u7684API\u3002<\/p><\/blockquote>\n<\/header>\n<h5 class=\"toc\"><span style=\"color: #000000;\"><strong>jira\u5e93\u3002<\/strong><\/span><\/h5>\n<blockquote>\n<div class=\"toc\">\u91cc\u9762\u6709jira\u767b\u5f55\uff0c\u4fee\u6539\uff0c\u65b0\u589eissue\u7684\u65b9\u6cd5<\/div>\n<\/blockquote>\n<h1>\u4ee3\u7801\u5b9e\u73b0<\/h1>\n<pre class=\"lang:python decode:true  EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\"># -*- coding: UTF-8 -*-\nimport datetime\nimport random\nimport gevent\nfrom gevent import monkey\nfrom jira import JIRA\nfrom model import addDefectDAO\nmonkey.patch_all()\nissue_list = []\ndef update(issue_key):\n    # \u4ea7\u751f\u4e00\u70b9\u5c0f\u5c0f\u7684\u95f4\u9694\uff0c\u907f\u514d\u4e00\u77ac\u95f4\u53d1\u51fa\u53bb100\u591a\u4e2a\u8bf7\u6c42\n    gevent.sleep(random.randint(1, 5) * 0.001)\n    global issue_list\n    starttime = datetime.datetime.now()\n    print(starttime)\n    print(\"start:\" + issue_key)\n    print(\"start:\" + issue_key)\n    issue = jira.issue(issue_key)\n    issue_dict = {\n        'summary': issue_key\n    }\n    try:\n        issue.update(fields=issue_dict)\n        issue_list.remove(issue_key)\n    except Exception:\n        pass\n    print(\"end:\" + issue_key)\n# \u4ece\u4e00\u4e2a\u672c\u5730\u6570\u636e\u5e93\u53d6\u51fa\u4e00\u5806issue\u7684\u4fe1\u606f,602\u662f\u672c\u5730\u7684project\u4fe1\u606f\u7f16\u53f7\nall = addDefectDAO.defect_select_not_draft_by_project_id(602)\nfor item in all:\n    issue_list.append(item[\"issue_key\"])\nurl = \"https:\/\/www.jira.com\"\nusername = \"username\"\npassword = \"password\"\njira = JIRA(server=url, basic_auth=(username, password), max_retries=0, timeout=400, async_=True, async_workers=5)\n# jira2 = Jira(url=url, username=username, password=password)\nprint(\"\u767b\u5f55\u6210\u529f\")\nstarttime = datetime.datetime.now()\napi_list = []\nwhile issue_list != []:\n    for i in issue_list:\n        api_list.append(gevent.spawn(update, i))\n    gevent.joinall(api_list)\nendtime = datetime.datetime.now()\nprint('\u603b\u8017\u65f6')\nprint((endtime - starttime).seconds)\nprint('*******')<\/code><\/pre>\n<h1>\u6ce8\u610f\u4e8b\u9879<\/h1>\n<p>1.\u9700\u8981\u5f15\u7528monkey.patch_all()<br \/>\n2.\u5f15\u7528monkey.patch_all()\u4e4b\u540e\u4f1a\u6709\u9519\u8bef\u4fe1\u606f:<\/p>\n<pre class=\"lang:python decode:true\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">UserWarning: libuv only supports millisecond timer resolution; all times less will be set to 1 ms<\/code><\/pre>\n<p>\u8fd9\u4e2a\u662f\u5df2\u77e5bug\uff0c\u572811\u670829\u65e5\u6709\u4eba\u5728github\u4e0a\u5df2\u7ecf\u63d0\u8fc7\u4e86\uff0c\u4f5c\u8005\u4f1a\u5728\u4e4b\u540e\u7684\u7248\u672c\u4fee\u6539\u3002\u76ee\u524d\u4e0d\u5f71\u54cd\u4f7f\u7528\u3002\u8bf7\u5ffd\u7565<br \/>\n3.\u901a\u8fc7\u8fd9\u6837\u7684\u65b9\u6cd5\u4fee\u6539\u4e4b\u540e\uff0c\u7ecf\u8fc7\u6211\u7684\u6d4b\u8bd5\uff0c\u901f\u5ea6\u5927\u6982\u5feb\u4e865\u500d\u4ee5\u4e0a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 \u56e0\u4e3a\u6211\u4eec\u672c\u5730\u6570\u636e\u5e93\u4e2d\u7ecf\u5e38\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u9700\u8981\u540c\u6b65\u81f3jira.\u8986\u76d6\u6389jira\u4e0a\u7684\u8001\u6570\u636e\u3002 \u56e0\u4e3aj [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":379,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jira","category-python"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=366"}],"version-history":[{"count":1,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":931,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/366\/revisions\/931"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/media\/379"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}