{"action":"created","comment":{"url":"https://api.github.com/repos/zendesk/samson/pulls/comments/61603872","id":61603872,"diff_hunk":"@@ -0,0 +1,47 @@\n+class CsvExport < ActiveRecord::Base\n+  belongs_to :user\n+  serialize :filters, JSON\n+  STATUS_VALUES = ['pending', 'started', 'finished', 'downloaded', 'failed', 'deleted']\n+\n+  before_destroy :delete_file\n+\n+  validates :status, inclusion: { in: STATUS_VALUES }\n+  delegate :email, to: :user, allow_nil: true\n+\n+\n+  scope :old, lambda {\n+    end_date = Rails.application.config.samson.export_job.downloaded_age.seconds.ago\n+    timeout_date = Rails.application.config.samson.export_job.max_age.seconds.ago\n+    where(\"(status = 'downloaded' AND updated_at <= :end_date) OR created_at <= :timeout_date\",\n+      end_date: end_date, timeout_date: timeout_date)\n+  }\n+\n+  def status?(state)\n+    'ready' == state.to_s ? ['downloaded', 'finished'].include?(status) : status == state.to_s\n+  end\n+\n+  def download_name\n+    \"deploys_#{created_at.to_s(:number)}.csv\"\n+  end\n+\n+  def path_file\n+    \"#{Rails.root}/export/#{id}\"\n+  end\n+\n+  def filters\n+    filter = super.clone\n+    if filter['deploys.created_at']\n+      dates = filter['deploys.created_at'].scan(/-?\\d+-\\d+-\\d+/)","path":"app/models/csv_export.rb","position":34,"original_position":34,"commit_id":"37db88f081cdfee585d2382dc7828280570ea372","original_commit_id":"37db88f081cdfee585d2382dc7828280570ea372","user":{"login":"grosser","id":11367,"avatar_url":"https://avatars.githubusercontent.com/u/11367?v=3","gravatar_id":"","url":"https://api.github.com/users/grosser","html_url":"https://github.com/grosser","followers_url":"https://api.github.com/users/grosser/followers","following_url":"https://api.github.com/users/grosser/following{/other_user}","gists_url":"https://api.github.com/users/grosser/gists{/gist_id}","starred_url":"https://api.github.com/users/grosser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grosser/subscriptions","organizations_url":"https://api.github.com/users/grosser/orgs","repos_url":"https://api.github.com/users/grosser/repos","events_url":"https://api.github.com/users/grosser/events{/privacy}","received_events_url":"https://api.github.com/users/grosser/received_events","type":"User","site_admin":false},"body":"should the controller handle this instead ... it does all the filtering, right ?","created_at":"2016-04-29T16:20:34Z","updated_at":"2016-04-29T16:20:34Z","html_url":"https://github.com/zendesk/samson/pull/766#discussion_r61603872","pull_request_url":"https://api.github.com/repos/zendesk/samson/pulls/766","_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments/61603872"},"html":{"href":"https://github.com/zendesk/samson/pull/766#discussion_r61603872"},"pull_request":{"href":"https://api.github.com/repos/zendesk/samson/pulls/766"}}},"pull_request":{"url":"https://api.github.com/repos/zendesk/samson/pulls/766","id":63412019,"html_url":"https://github.com/zendesk/samson/pull/766","diff_url":"https://github.com/zendesk/samson/pull/766.diff","patch_url":"https://github.com/zendesk/samson/pull/766.patch","issue_url":"https://api.github.com/repos/zendesk/samson/issues/766","number":766,"state":"open","locked":false,"title":"Move deploys csv export to an asynchronous job","user":{"login":"rikeoka","id":11447948,"avatar_url":"https://avatars.githubusercontent.com/u/11447948?v=3","gravatar_id":"","url":"https://api.github.com/users/rikeoka","html_url":"https://github.com/rikeoka","followers_url":"https://api.github.com/users/rikeoka/followers","following_url":"https://api.github.com/users/rikeoka/following{/other_user}","gists_url":"https://api.github.com/users/rikeoka/gists{/gist_id}","starred_url":"https://api.github.com/users/rikeoka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rikeoka/subscriptions","organizations_url":"https://api.github.com/users/rikeoka/orgs","repos_url":"https://api.github.com/users/rikeoka/repos","events_url":"https://api.github.com/users/rikeoka/events{/privacy}","received_events_url":"https://api.github.com/users/rikeoka/received_events","type":"User","site_admin":false},"body":"* The deploys report was failing to generate realtime with a large number of records.  The report is now generated in a background job.  The stored files is cleaned up the next time a CSV Job is run, when it is older than the lessor of 12 hours after download or 1 month after creation.\r\n\r\n* UI changes.\r\nHeader - Added reports to Admin menu (Admin menu now shows for all users but only shows Admin options if admin, reporting is one such non-admin task):\r\n<img width=\"328\" alt=\"screen shot 2016-03-11 at 1 38 20 pm\" src=\"https://cloud.githubusercontent.com/assets/11447948/13716249/c78f73e6-e78e-11e5-8ff8-e7614bc03ab6.png\">\r\n\r\nRecent Deploys:\r\n![screen shot 2016-02-24 at 11 50 24 am](https://cloud.githubusercontent.com/assets/11447948/13298833/460ab8e2-daed-11e5-8592-57e2728676f6.png)\r\n\r\nNew CSV pages:\r\n/csv\r\n![screen shot 2016-02-24 at 11 50 59 am](https://cloud.githubusercontent.com/assets/11447948/13298853/5bfbcdda-daed-11e5-9a30-4d5030b59cf8.png)\r\n\r\n/csv/new\r\n![screen shot 2016-02-24 at 11 51 05 am](https://cloud.githubusercontent.com/assets/11447948/13298869/6b88a62e-daed-11e5-8878-008b3364d33c.png)\r\n\r\n/csv/status/:id\r\n![screen shot 2016-03-18 at 10 44 11 am](https://cloud.githubusercontent.com/assets/11447948/13886886/63e1ec58-ecf6-11e5-8cd6-a0bcb252cf00.png)\r\n![screen shot 2016-03-18 at 10 44 48 am](https://cloud.githubusercontent.com/assets/11447948/13886908/7a427ba2-ecf6-11e5-8acb-71e0a51bfa03.png)\r\n\r\n\r\n/cc @zendesk/samson\r\n\r\n### Tasks\r\n - [ ] :+1: from team\r\n\r\n### References\r\nMoved code branch from forked repo to zendesk repo to ease review per @grosser .  \r\nOriginal PR https://github.com/zendesk/samson/pull/747 \r\n\r\n### Risks\r\n- Level: Med\r\n","created_at":"2016-03-18T17:49:04Z","updated_at":"2016-04-29T16:20:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52cc28875f42c7f03f81eb6e63d7821e194eca9e","assignee":{"login":"rikeoka","id":11447948,"avatar_url":"https://avatars.githubusercontent.com/u/11447948?v=3","gravatar_id":"","url":"https://api.github.com/users/rikeoka","html_url":"https://github.com/rikeoka","followers_url":"https://api.github.com/users/rikeoka/followers","following_url":"https://api.github.com/users/rikeoka/following{/other_user}","gists_url":"https://api.github.com/users/rikeoka/gists{/gist_id}","starred_url":"https://api.github.com/users/rikeoka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rikeoka/subscriptions","organizations_url":"https://api.github.com/users/rikeoka/orgs","repos_url":"https://api.github.com/users/rikeoka/repos","events_url":"https://api.github.com/users/rikeoka/events{/privacy}","received_events_url":"https://api.github.com/users/rikeoka/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/zendesk/samson/pulls/766/commits","review_comments_url":"https://api.github.com/repos/zendesk/samson/pulls/766/comments","review_comment_url":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zendesk/samson/issues/766/comments","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/37db88f081cdfee585d2382dc7828280570ea372","head":{"label":"zendesk:rikeoka/asynchronous_csv","ref":"rikeoka/asynchronous_csv","sha":"37db88f081cdfee585d2382dc7828280570ea372","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-04-29T07:38:19Z","pushed_at":"2016-04-29T16:17:42Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":174583,"stargazers_count":661,"watchers_count":661,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":111,"mirror_url":null,"open_issues_count":56,"forks":111,"open_issues":56,"watchers":661,"default_branch":"master"}},"base":{"label":"zendesk:master","ref":"master","sha":"079f16bb20edc8b6eef80f200fd4085ecc7d3c09","user":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"repo":{"id":20208662,"name":"samson","full_name":"zendesk/samson","owner":{"login":"zendesk","id":11525,"avatar_url":"https://avatars.githubusercontent.com/u/11525?v=3","gravatar_id":"","url":"https://api.github.com/users/zendesk","html_url":"https://github.com/zendesk","followers_url":"https://api.github.com/users/zendesk/followers","following_url":"https://api.github.com/users/zendesk/following{/other_user}","gists_url":"https://api.github.com/users/zendesk/gists{/gist_id}","starred_url":"https://api.github.com/users/zendesk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zendesk/subscriptions","organizations_url":"https://api.github.com/users/zendesk/orgs","repos_url":"https://api.github.com/users/zendesk/repos","events_url":"https://api.github.com/users/zendesk/events{/privacy}","received_events_url":"https://api.github.com/users/zendesk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zendesk/samson","description":"Web interface for deployments","fork":false,"url":"https://api.github.com/repos/zendesk/samson","forks_url":"https://api.github.com/repos/zendesk/samson/forks","keys_url":"https://api.github.com/repos/zendesk/samson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zendesk/samson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zendesk/samson/teams","hooks_url":"https://api.github.com/repos/zendesk/samson/hooks","issue_events_url":"https://api.github.com/repos/zendesk/samson/issues/events{/number}","events_url":"https://api.github.com/repos/zendesk/samson/events","assignees_url":"https://api.github.com/repos/zendesk/samson/assignees{/user}","branches_url":"https://api.github.com/repos/zendesk/samson/branches{/branch}","tags_url":"https://api.github.com/repos/zendesk/samson/tags","blobs_url":"https://api.github.com/repos/zendesk/samson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zendesk/samson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zendesk/samson/git/refs{/sha}","trees_url":"https://api.github.com/repos/zendesk/samson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zendesk/samson/statuses/{sha}","languages_url":"https://api.github.com/repos/zendesk/samson/languages","stargazers_url":"https://api.github.com/repos/zendesk/samson/stargazers","contributors_url":"https://api.github.com/repos/zendesk/samson/contributors","subscribers_url":"https://api.github.com/repos/zendesk/samson/subscribers","subscription_url":"https://api.github.com/repos/zendesk/samson/subscription","commits_url":"https://api.github.com/repos/zendesk/samson/commits{/sha}","git_commits_url":"https://api.github.com/repos/zendesk/samson/git/commits{/sha}","comments_url":"https://api.github.com/repos/zendesk/samson/comments{/number}","issue_comment_url":"https://api.github.com/repos/zendesk/samson/issues/comments{/number}","contents_url":"https://api.github.com/repos/zendesk/samson/contents/{+path}","compare_url":"https://api.github.com/repos/zendesk/samson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zendesk/samson/merges","archive_url":"https://api.github.com/repos/zendesk/samson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zendesk/samson/downloads","issues_url":"https://api.github.com/repos/zendesk/samson/issues{/number}","pulls_url":"https://api.github.com/repos/zendesk/samson/pulls{/number}","milestones_url":"https://api.github.com/repos/zendesk/samson/milestones{/number}","notifications_url":"https://api.github.com/repos/zendesk/samson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zendesk/samson/labels{/name}","releases_url":"https://api.github.com/repos/zendesk/samson/releases{/id}","deployments_url":"https://api.github.com/repos/zendesk/samson/deployments","created_at":"2014-05-27T05:55:57Z","updated_at":"2016-04-29T07:38:19Z","pushed_at":"2016-04-29T16:17:42Z","git_url":"git://github.com/zendesk/samson.git","ssh_url":"git@github.com:zendesk/samson.git","clone_url":"https://github.com/zendesk/samson.git","svn_url":"https://github.com/zendesk/samson","homepage":null,"size":174583,"stargazers_count":661,"watchers_count":661,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":111,"mirror_url":null,"open_issues_count":56,"forks":111,"open_issues":56,"watchers":661,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zendesk/samson/pulls/766"},"html":{"href":"https://github.com/zendesk/samson/pull/766"},"issue":{"href":"https://api.github.com/repos/zendesk/samson/issues/766"},"comments":{"href":"https://api.github.com/repos/zendesk/samson/issues/766/comments"},"review_comments":{"href":"https://api.github.com/repos/zendesk/samson/pulls/766/comments"},"review_comment":{"href":"https://api.github.com/repos/zendesk/samson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zendesk/samson/pulls/766/commits"},"statuses":{"href":"https://api.github.com/repos/zendesk/samson/statuses/37db88f081cdfee585d2382dc7828280570ea372"}}}}