{"action":"created","comment":{"url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/comments/197192167","pull_request_review_id":130888514,"id":197192167,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5NzE5MjE2Nw==","diff_hunk":"@@ -59,7 +62,13 @@ def run(self):\n                 instance.process_job(self)\n \n         try:\n-            result = self.get_fn().fn(*self.args, **self.kwargs)\n+            task = self.get_task_instance()\n+\n+            if task.atomic:\n+                with transaction.atomic():\n+                    result = task.fn(*self.args, **self.kwargs)\n+            else:\n+                result = task.fn(*self.args, **self.kwargs)","path":"django_lightweight_queue/job.py","position":21,"original_position":21,"commit_id":"42dbca4b5e9204d599817b209d5c80f57f265e6a","original_commit_id":"42dbca4b5e9204d599817b209d5c80f57f265e6a","user":{"login":"prophile","id":35525,"node_id":"MDQ6VXNlcjM1NTI1","avatar_url":"https://avatars3.githubusercontent.com/u/35525?v=4","gravatar_id":"","url":"https://api.github.com/users/prophile","html_url":"https://github.com/prophile","followers_url":"https://api.github.com/users/prophile/followers","following_url":"https://api.github.com/users/prophile/following{/other_user}","gists_url":"https://api.github.com/users/prophile/gists{/gist_id}","starred_url":"https://api.github.com/users/prophile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prophile/subscriptions","organizations_url":"https://api.github.com/users/prophile/orgs","repos_url":"https://api.github.com/users/prophile/repos","events_url":"https://api.github.com/users/prophile/events{/privacy}","received_events_url":"https://api.github.com/users/prophile/received_events","type":"User","site_admin":false},"body":"I considered this but decided against it because:\r\n\r\n1. It takes more lines of code in total (due to having to define `dummy`),\r\n2. I was worried it makes it slightly less clear what's going on: it looks like there's a context manager that gets run in every case, one has to go to the definition of dummy (or at least infer from the name) that it has no action.\r\n\r\nAlso thought about factoring out the call, either by doing:\r\n\r\n```python\r\ndef run():\r\n    nonlocal result\r\n    result = task.fn(*self.args, **self.kwargs)\r\n\r\nif task.atomic:\r\n    with transaction.atomic():\r\n        run()\r\nelse:\r\n    run()\r\n```\r\n\r\nor:\r\n\r\n```python\r\nrun = functools.partial(task.fn, *self.args, **self.kwargs)\r\n\r\nif task.atomic:\r\n    with transaction.atomic():\r\n        result = run()\r\nelse:\r\n    result = run()\r\n```\r\n\r\nEither is fine but I felt like the original spelling was a little clearer, even though it unfortunately means some duplication.\r\n\r\nOpen to changing this if you have another way of spelling it though!","created_at":"2018-06-21T16:09:47Z","updated_at":"2018-06-21T16:09:47Z","html_url":"https://github.com/thread/django-lightweight-queue/pull/26#discussion_r197192167","pull_request_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/comments/197192167"},"html":{"href":"https://github.com/thread/django-lightweight-queue/pull/26#discussion_r197192167"},"pull_request":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26"}},"in_reply_to_id":197184526},"pull_request":{"url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26","id":196494980,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk2NDk0OTgw","html_url":"https://github.com/thread/django-lightweight-queue/pull/26","diff_url":"https://github.com/thread/django-lightweight-queue/pull/26.diff","patch_url":"https://github.com/thread/django-lightweight-queue/pull/26.patch","issue_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/26","number":26,"state":"open","locked":false,"title":"Per-task atomicity","user":{"login":"prophile","id":35525,"node_id":"MDQ6VXNlcjM1NTI1","avatar_url":"https://avatars3.githubusercontent.com/u/35525?v=4","gravatar_id":"","url":"https://api.github.com/users/prophile","html_url":"https://github.com/prophile","followers_url":"https://api.github.com/users/prophile/followers","following_url":"https://api.github.com/users/prophile/following{/other_user}","gists_url":"https://api.github.com/users/prophile/gists{/gist_id}","starred_url":"https://api.github.com/users/prophile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prophile/subscriptions","organizations_url":"https://api.github.com/users/prophile/orgs","repos_url":"https://api.github.com/users/prophile/repos","events_url":"https://api.github.com/users/prophile/events{/privacy}","received_events_url":"https://api.github.com/users/prophile/received_events","type":"User","site_admin":false},"body":"This adds a mechanism by which a task can be marked atomic or non-atomic on a case by case basis.\n\nThe middleware didn't have any useful way of partitioning this by request.\n\nRather than add a mechanism of passing around arbitrary metadata to middlewares, this was the easier option. This PR is backwards-compatible in that the old middleware still exists and the  \nall-tasks-are-atomic option is changeable via a setting.","created_at":"2018-06-21T15:40:14Z","updated_at":"2018-06-21T16:09:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9969b31077023288b4d42b5ac77863bca49e539a","assignee":null,"assignees":[],"requested_reviewers":[{"login":"PeterJCLaw","id":336212,"node_id":"MDQ6VXNlcjMzNjIxMg==","avatar_url":"https://avatars2.githubusercontent.com/u/336212?v=4","gravatar_id":"","url":"https://api.github.com/users/PeterJCLaw","html_url":"https://github.com/PeterJCLaw","followers_url":"https://api.github.com/users/PeterJCLaw/followers","following_url":"https://api.github.com/users/PeterJCLaw/following{/other_user}","gists_url":"https://api.github.com/users/PeterJCLaw/gists{/gist_id}","starred_url":"https://api.github.com/users/PeterJCLaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PeterJCLaw/subscriptions","organizations_url":"https://api.github.com/users/PeterJCLaw/orgs","repos_url":"https://api.github.com/users/PeterJCLaw/repos","events_url":"https://api.github.com/users/PeterJCLaw/events{/privacy}","received_events_url":"https://api.github.com/users/PeterJCLaw/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26/commits","review_comments_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26/comments","review_comment_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/26/comments","statuses_url":"https://api.github.com/repos/thread/django-lightweight-queue/statuses/42dbca4b5e9204d599817b209d5c80f57f265e6a","head":{"label":"thread:atomic-flag","ref":"atomic-flag","sha":"42dbca4b5e9204d599817b209d5c80f57f265e6a","user":{"login":"thread","id":1985527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5ODU1Mjc=","avatar_url":"https://avatars1.githubusercontent.com/u/1985527?v=4","gravatar_id":"","url":"https://api.github.com/users/thread","html_url":"https://github.com/thread","followers_url":"https://api.github.com/users/thread/followers","following_url":"https://api.github.com/users/thread/following{/other_user}","gists_url":"https://api.github.com/users/thread/gists{/gist_id}","starred_url":"https://api.github.com/users/thread/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thread/subscriptions","organizations_url":"https://api.github.com/users/thread/orgs","repos_url":"https://api.github.com/users/thread/repos","events_url":"https://api.github.com/users/thread/events{/privacy}","received_events_url":"https://api.github.com/users/thread/received_events","type":"Organization","site_admin":false},"repo":{"id":5173487,"node_id":"MDEwOlJlcG9zaXRvcnk1MTczNDg3","name":"django-lightweight-queue","full_name":"thread/django-lightweight-queue","owner":{"login":"thread","id":1985527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5ODU1Mjc=","avatar_url":"https://avatars1.githubusercontent.com/u/1985527?v=4","gravatar_id":"","url":"https://api.github.com/users/thread","html_url":"https://github.com/thread","followers_url":"https://api.github.com/users/thread/followers","following_url":"https://api.github.com/users/thread/following{/other_user}","gists_url":"https://api.github.com/users/thread/gists{/gist_id}","starred_url":"https://api.github.com/users/thread/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thread/subscriptions","organizations_url":"https://api.github.com/users/thread/orgs","repos_url":"https://api.github.com/users/thread/repos","events_url":"https://api.github.com/users/thread/events{/privacy}","received_events_url":"https://api.github.com/users/thread/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thread/django-lightweight-queue","description":"Lightweight & modular queue and cron system for Django","fork":false,"url":"https://api.github.com/repos/thread/django-lightweight-queue","forks_url":"https://api.github.com/repos/thread/django-lightweight-queue/forks","keys_url":"https://api.github.com/repos/thread/django-lightweight-queue/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thread/django-lightweight-queue/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thread/django-lightweight-queue/teams","hooks_url":"https://api.github.com/repos/thread/django-lightweight-queue/hooks","issue_events_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/events{/number}","events_url":"https://api.github.com/repos/thread/django-lightweight-queue/events","assignees_url":"https://api.github.com/repos/thread/django-lightweight-queue/assignees{/user}","branches_url":"https://api.github.com/repos/thread/django-lightweight-queue/branches{/branch}","tags_url":"https://api.github.com/repos/thread/django-lightweight-queue/tags","blobs_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/refs{/sha}","trees_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thread/django-lightweight-queue/statuses/{sha}","languages_url":"https://api.github.com/repos/thread/django-lightweight-queue/languages","stargazers_url":"https://api.github.com/repos/thread/django-lightweight-queue/stargazers","contributors_url":"https://api.github.com/repos/thread/django-lightweight-queue/contributors","subscribers_url":"https://api.github.com/repos/thread/django-lightweight-queue/subscribers","subscription_url":"https://api.github.com/repos/thread/django-lightweight-queue/subscription","commits_url":"https://api.github.com/repos/thread/django-lightweight-queue/commits{/sha}","git_commits_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/commits{/sha}","comments_url":"https://api.github.com/repos/thread/django-lightweight-queue/comments{/number}","issue_comment_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/comments{/number}","contents_url":"https://api.github.com/repos/thread/django-lightweight-queue/contents/{+path}","compare_url":"https://api.github.com/repos/thread/django-lightweight-queue/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thread/django-lightweight-queue/merges","archive_url":"https://api.github.com/repos/thread/django-lightweight-queue/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thread/django-lightweight-queue/downloads","issues_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues{/number}","pulls_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls{/number}","milestones_url":"https://api.github.com/repos/thread/django-lightweight-queue/milestones{/number}","notifications_url":"https://api.github.com/repos/thread/django-lightweight-queue/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thread/django-lightweight-queue/labels{/name}","releases_url":"https://api.github.com/repos/thread/django-lightweight-queue/releases{/id}","deployments_url":"https://api.github.com/repos/thread/django-lightweight-queue/deployments","created_at":"2012-07-25T01:38:31Z","updated_at":"2018-06-12T15:50:13Z","pushed_at":"2018-06-21T15:40:14Z","git_url":"git://github.com/thread/django-lightweight-queue.git","ssh_url":"git@github.com:thread/django-lightweight-queue.git","clone_url":"https://github.com/thread/django-lightweight-queue.git","svn_url":"https://github.com/thread/django-lightweight-queue","homepage":"","size":197,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":3,"open_issues":1,"watchers":16,"default_branch":"master"}},"base":{"label":"thread:master","ref":"master","sha":"835bfbd06d37e3251f6542f45c1dd113122ff35c","user":{"login":"thread","id":1985527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5ODU1Mjc=","avatar_url":"https://avatars1.githubusercontent.com/u/1985527?v=4","gravatar_id":"","url":"https://api.github.com/users/thread","html_url":"https://github.com/thread","followers_url":"https://api.github.com/users/thread/followers","following_url":"https://api.github.com/users/thread/following{/other_user}","gists_url":"https://api.github.com/users/thread/gists{/gist_id}","starred_url":"https://api.github.com/users/thread/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thread/subscriptions","organizations_url":"https://api.github.com/users/thread/orgs","repos_url":"https://api.github.com/users/thread/repos","events_url":"https://api.github.com/users/thread/events{/privacy}","received_events_url":"https://api.github.com/users/thread/received_events","type":"Organization","site_admin":false},"repo":{"id":5173487,"node_id":"MDEwOlJlcG9zaXRvcnk1MTczNDg3","name":"django-lightweight-queue","full_name":"thread/django-lightweight-queue","owner":{"login":"thread","id":1985527,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE5ODU1Mjc=","avatar_url":"https://avatars1.githubusercontent.com/u/1985527?v=4","gravatar_id":"","url":"https://api.github.com/users/thread","html_url":"https://github.com/thread","followers_url":"https://api.github.com/users/thread/followers","following_url":"https://api.github.com/users/thread/following{/other_user}","gists_url":"https://api.github.com/users/thread/gists{/gist_id}","starred_url":"https://api.github.com/users/thread/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thread/subscriptions","organizations_url":"https://api.github.com/users/thread/orgs","repos_url":"https://api.github.com/users/thread/repos","events_url":"https://api.github.com/users/thread/events{/privacy}","received_events_url":"https://api.github.com/users/thread/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thread/django-lightweight-queue","description":"Lightweight & modular queue and cron system for Django","fork":false,"url":"https://api.github.com/repos/thread/django-lightweight-queue","forks_url":"https://api.github.com/repos/thread/django-lightweight-queue/forks","keys_url":"https://api.github.com/repos/thread/django-lightweight-queue/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thread/django-lightweight-queue/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thread/django-lightweight-queue/teams","hooks_url":"https://api.github.com/repos/thread/django-lightweight-queue/hooks","issue_events_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/events{/number}","events_url":"https://api.github.com/repos/thread/django-lightweight-queue/events","assignees_url":"https://api.github.com/repos/thread/django-lightweight-queue/assignees{/user}","branches_url":"https://api.github.com/repos/thread/django-lightweight-queue/branches{/branch}","tags_url":"https://api.github.com/repos/thread/django-lightweight-queue/tags","blobs_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/refs{/sha}","trees_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thread/django-lightweight-queue/statuses/{sha}","languages_url":"https://api.github.com/repos/thread/django-lightweight-queue/languages","stargazers_url":"https://api.github.com/repos/thread/django-lightweight-queue/stargazers","contributors_url":"https://api.github.com/repos/thread/django-lightweight-queue/contributors","subscribers_url":"https://api.github.com/repos/thread/django-lightweight-queue/subscribers","subscription_url":"https://api.github.com/repos/thread/django-lightweight-queue/subscription","commits_url":"https://api.github.com/repos/thread/django-lightweight-queue/commits{/sha}","git_commits_url":"https://api.github.com/repos/thread/django-lightweight-queue/git/commits{/sha}","comments_url":"https://api.github.com/repos/thread/django-lightweight-queue/comments{/number}","issue_comment_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues/comments{/number}","contents_url":"https://api.github.com/repos/thread/django-lightweight-queue/contents/{+path}","compare_url":"https://api.github.com/repos/thread/django-lightweight-queue/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thread/django-lightweight-queue/merges","archive_url":"https://api.github.com/repos/thread/django-lightweight-queue/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thread/django-lightweight-queue/downloads","issues_url":"https://api.github.com/repos/thread/django-lightweight-queue/issues{/number}","pulls_url":"https://api.github.com/repos/thread/django-lightweight-queue/pulls{/number}","milestones_url":"https://api.github.com/repos/thread/django-lightweight-queue/milestones{/number}","notifications_url":"https://api.github.com/repos/thread/django-lightweight-queue/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thread/django-lightweight-queue/labels{/name}","releases_url":"https://api.github.com/repos/thread/django-lightweight-queue/releases{/id}","deployments_url":"https://api.github.com/repos/thread/django-lightweight-queue/deployments","created_at":"2012-07-25T01:38:31Z","updated_at":"2018-06-12T15:50:13Z","pushed_at":"2018-06-21T15:40:14Z","git_url":"git://github.com/thread/django-lightweight-queue.git","ssh_url":"git@github.com:thread/django-lightweight-queue.git","clone_url":"https://github.com/thread/django-lightweight-queue.git","svn_url":"https://github.com/thread/django-lightweight-queue","homepage":"","size":197,"stargazers_count":16,"watchers_count":16,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":3,"open_issues":1,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26"},"html":{"href":"https://github.com/thread/django-lightweight-queue/pull/26"},"issue":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/issues/26"},"comments":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/thread/django-lightweight-queue/statuses/42dbca4b5e9204d599817b209d5c80f57f265e6a"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"prophile"}}