{"action":"created","issue":{"url":"https://api.github.com/repos/OptimalBits/bull/issues/232","repository_url":"https://api.github.com/repos/OptimalBits/bull","labels_url":"https://api.github.com/repos/OptimalBits/bull/issues/232/labels{/name}","comments_url":"https://api.github.com/repos/OptimalBits/bull/issues/232/comments","events_url":"https://api.github.com/repos/OptimalBits/bull/issues/232/events","html_url":"https://github.com/OptimalBits/bull/pull/232","id":131180678,"number":232,"title":"Repeatable jobs","user":{"login":"jozsi","id":840815,"avatar_url":"https://avatars.githubusercontent.com/u/840815?v=3","gravatar_id":"","url":"https://api.github.com/users/jozsi","html_url":"https://github.com/jozsi","followers_url":"https://api.github.com/users/jozsi/followers","following_url":"https://api.github.com/users/jozsi/following{/other_user}","gists_url":"https://api.github.com/users/jozsi/gists{/gist_id}","starred_url":"https://api.github.com/users/jozsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jozsi/subscriptions","organizations_url":"https://api.github.com/users/jozsi/orgs","repos_url":"https://api.github.com/users/jozsi/repos","events_url":"https://api.github.com/users/jozsi/events{/privacy}","received_events_url":"https://api.github.com/users/jozsi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-02-03T22:52:22Z","updated_at":"2016-06-06T11:27:28Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/OptimalBits/bull/pulls/232","html_url":"https://github.com/OptimalBits/bull/pull/232","diff_url":"https://github.com/OptimalBits/bull/pull/232.diff","patch_url":"https://github.com/OptimalBits/bull/pull/232.patch"},"body":"Hello,\r\n\r\nI am having a hard time figuring out how to correctly implement a repeatable job. I've tried multiple scenarios:\r\n- once the job has completed, add a new delayed one to the queue\r\n- using retry before/after completion\r\n\r\nWhat would be the correct flow to achieve repeatabiliy?"},"comment":{"url":"https://api.github.com/repos/OptimalBits/bull/issues/comments/223933062","html_url":"https://github.com/OptimalBits/bull/pull/232#issuecomment-223933062","issue_url":"https://api.github.com/repos/OptimalBits/bull/issues/232","id":223933062,"user":{"login":"jozsi","id":840815,"avatar_url":"https://avatars.githubusercontent.com/u/840815?v=3","gravatar_id":"","url":"https://api.github.com/users/jozsi","html_url":"https://github.com/jozsi","followers_url":"https://api.github.com/users/jozsi/followers","following_url":"https://api.github.com/users/jozsi/following{/other_user}","gists_url":"https://api.github.com/users/jozsi/gists{/gist_id}","starred_url":"https://api.github.com/users/jozsi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jozsi/subscriptions","organizations_url":"https://api.github.com/users/jozsi/orgs","repos_url":"https://api.github.com/users/jozsi/repos","events_url":"https://api.github.com/users/jozsi/events{/privacy}","received_events_url":"https://api.github.com/users/jozsi/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T11:27:28Z","updated_at":"2016-06-06T11:27:28Z","body":"@ivasilov - I ended up using this (it uses internal methods, use it at your own risk):\r\n```javascript\r\nconst Queue = require('bull');\r\nconst co = require('co');\r\n\r\nQueue.prototype.repeat = co.wrap(function*(data, opts) {\r\n  this.on('completed', (job, result) => {\r\n    this.client.sremAsync(this.toKey('completed'), job.jobId)\r\n      .then(() => job._addToDelayed(Date.now() + opts.delay));\r\n  });\r\n\r\n  let job;\r\n  const count = yield this.getJobCountByTypes('paused', 'delayed', 'wait', 'active');\r\n  if (count) {\r\n    const id = yield this.client.getAsync(this.toKey('id'));\r\n    job = yield this.getJob(id);\r\n  }\r\n\r\n  return job || this.add(data, opts);\r\n});\r\n\r\nrequire('./jobs/bt')(Queue, 'bt')\r\n  .repeat({}, {\r\n    delay: 5 * 60 * 1000\r\n  })\r\n  .catch(console.error);\r\n```"}}
{"actor":{"display_login":"jozsi"}}