{"action":"created","comment":{"url":"https://api.github.com/repos/zensum/scheduler/pulls/comments/166326710","pull_request_review_id":94370371,"id":166326710,"diff_hunk":"@@ -48,27 +67,48 @@ class Queue {\n \n fun queueWorker(q: Queue, onItem: suspend (ScheduledTask) -> Unit) = Thread { runBlocking {\n     while(!q.closed()) {\n-        onItem(q.take())\n+        val item = q.take()\n+        onItem(item)\n+        updateQueue(item, q)\n     }\n }}.also { it.start() }\n \n-private val logger = KotlinLogging.logger(\"scheduler\")\n+private fun updateQueue(item: ScheduledTask, q: Queue) {\n+    val nextInstance: ScheduledTask? = item.nextInstance()\n+    if (nextInstance == null) {\n+        synchronized(item) {\n+            removed.remove(item.idAsString())\n+        }\n+    } else {\n+        q.add(nextInstance)\n+    }\n+}\n \n private val producer = ProducerBuilder.ofByteArray.create()\n suspend fun publish(t: ScheduledTask) {\n-    val found = idem.contains(t.idAsString())\n-    if (found) {\n+    if (!t.isRepeating() && idem.contains(t.idAsString())) {\n+        return\n+    }\n+    val isRemoved = removed.get(t.idAsString())\n+    if (isRemoved != null && isRemoved) {\n         return\n     }\n     val d = t.data()\n+    val prodMS = System.currentTimeMillis()\n     producer.send(d.topic, d.key, d.body.toByteArray())\n+    val afterMS = System.currentTimeMillis()\n+\n+    val prodTook = afterMS - prodMS\n+\n     idem.put(t.idAsString())\n     logger.info {\n         val delta = t.getDelay(TimeUnit.MILLISECONDS)\n-        \"Published task ${t.idAsString()} delta = $delta\"\n+        \"Published task ${t.idAsString()} delta = $delta repeating=${t.isRepeating()} expired=${t.isExpired()} took=$prodMS prodTook=$prodTook\"\n     }\n }\n \n+var removed: MutableMap<String, Boolean> = HashMap()","path":"src/main/kotlin/Main.kt","position":113,"original_position":113,"commit_id":"7fc8497175f94fd823ecf79434fe987abeb25098","original_commit_id":"7fc8497175f94fd823ecf79434fe987abeb25098","user":{"login":"williamhogman","id":143746,"avatar_url":"https://avatars2.githubusercontent.com/u/143746?v=4","gravatar_id":"","url":"https://api.github.com/users/williamhogman","html_url":"https://github.com/williamhogman","followers_url":"https://api.github.com/users/williamhogman/followers","following_url":"https://api.github.com/users/williamhogman/following{/other_user}","gists_url":"https://api.github.com/users/williamhogman/gists{/gist_id}","starred_url":"https://api.github.com/users/williamhogman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williamhogman/subscriptions","organizations_url":"https://api.github.com/users/williamhogman/orgs","repos_url":"https://api.github.com/users/williamhogman/repos","events_url":"https://api.github.com/users/williamhogman/events{/privacy}","received_events_url":"https://api.github.com/users/williamhogman/received_events","type":"User","site_admin":false},"body":"Replace with `ConcurrentHashMap`","created_at":"2018-02-06T14:52:09Z","updated_at":"2018-02-06T14:57:52Z","html_url":"https://github.com/zensum/scheduler/pull/1#discussion_r166326710","pull_request_url":"https://api.github.com/repos/zensum/scheduler/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/comments/166326710"},"html":{"href":"https://github.com/zensum/scheduler/pull/1#discussion_r166326710"},"pull_request":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/zensum/scheduler/pulls/1","id":167433275,"html_url":"https://github.com/zensum/scheduler/pull/1","diff_url":"https://github.com/zensum/scheduler/pull/1.diff","patch_url":"https://github.com/zensum/scheduler/pull/1.patch","issue_url":"https://api.github.com/repos/zensum/scheduler/issues/1","number":1,"state":"open","locked":false,"title":"Feature repeating","user":{"login":"Torbacka","id":6124478,"avatar_url":"https://avatars0.githubusercontent.com/u/6124478?v=4","gravatar_id":"","url":"https://api.github.com/users/Torbacka","html_url":"https://github.com/Torbacka","followers_url":"https://api.github.com/users/Torbacka/followers","following_url":"https://api.github.com/users/Torbacka/following{/other_user}","gists_url":"https://api.github.com/users/Torbacka/gists{/gist_id}","starred_url":"https://api.github.com/users/Torbacka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Torbacka/subscriptions","organizations_url":"https://api.github.com/users/Torbacka/orgs","repos_url":"https://api.github.com/users/Torbacka/repos","events_url":"https://api.github.com/users/Torbacka/events{/privacy}","received_events_url":"https://api.github.com/users/Torbacka/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-02-06T14:45:25Z","updated_at":"2018-02-06T14:57:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82cd8c3cbe976ea51679f20165cf3b9fef34d11c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/zensum/scheduler/pulls/1/commits","review_comments_url":"https://api.github.com/repos/zensum/scheduler/pulls/1/comments","review_comment_url":"https://api.github.com/repos/zensum/scheduler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zensum/scheduler/issues/1/comments","statuses_url":"https://api.github.com/repos/zensum/scheduler/statuses/7fc8497175f94fd823ecf79434fe987abeb25098","head":{"label":"zensum:feature-repeating","ref":"feature-repeating","sha":"7fc8497175f94fd823ecf79434fe987abeb25098","user":{"login":"zensum","id":6458660,"avatar_url":"https://avatars3.githubusercontent.com/u/6458660?v=4","gravatar_id":"","url":"https://api.github.com/users/zensum","html_url":"https://github.com/zensum","followers_url":"https://api.github.com/users/zensum/followers","following_url":"https://api.github.com/users/zensum/following{/other_user}","gists_url":"https://api.github.com/users/zensum/gists{/gist_id}","starred_url":"https://api.github.com/users/zensum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zensum/subscriptions","organizations_url":"https://api.github.com/users/zensum/orgs","repos_url":"https://api.github.com/users/zensum/repos","events_url":"https://api.github.com/users/zensum/events{/privacy}","received_events_url":"https://api.github.com/users/zensum/received_events","type":"Organization","site_admin":false},"repo":{"id":107602473,"name":"scheduler","full_name":"zensum/scheduler","owner":{"login":"zensum","id":6458660,"avatar_url":"https://avatars3.githubusercontent.com/u/6458660?v=4","gravatar_id":"","url":"https://api.github.com/users/zensum","html_url":"https://github.com/zensum","followers_url":"https://api.github.com/users/zensum/followers","following_url":"https://api.github.com/users/zensum/following{/other_user}","gists_url":"https://api.github.com/users/zensum/gists{/gist_id}","starred_url":"https://api.github.com/users/zensum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zensum/subscriptions","organizations_url":"https://api.github.com/users/zensum/orgs","repos_url":"https://api.github.com/users/zensum/repos","events_url":"https://api.github.com/users/zensum/events{/privacy}","received_events_url":"https://api.github.com/users/zensum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zensum/scheduler","description":null,"fork":false,"url":"https://api.github.com/repos/zensum/scheduler","forks_url":"https://api.github.com/repos/zensum/scheduler/forks","keys_url":"https://api.github.com/repos/zensum/scheduler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zensum/scheduler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zensum/scheduler/teams","hooks_url":"https://api.github.com/repos/zensum/scheduler/hooks","issue_events_url":"https://api.github.com/repos/zensum/scheduler/issues/events{/number}","events_url":"https://api.github.com/repos/zensum/scheduler/events","assignees_url":"https://api.github.com/repos/zensum/scheduler/assignees{/user}","branches_url":"https://api.github.com/repos/zensum/scheduler/branches{/branch}","tags_url":"https://api.github.com/repos/zensum/scheduler/tags","blobs_url":"https://api.github.com/repos/zensum/scheduler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zensum/scheduler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zensum/scheduler/git/refs{/sha}","trees_url":"https://api.github.com/repos/zensum/scheduler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zensum/scheduler/statuses/{sha}","languages_url":"https://api.github.com/repos/zensum/scheduler/languages","stargazers_url":"https://api.github.com/repos/zensum/scheduler/stargazers","contributors_url":"https://api.github.com/repos/zensum/scheduler/contributors","subscribers_url":"https://api.github.com/repos/zensum/scheduler/subscribers","subscription_url":"https://api.github.com/repos/zensum/scheduler/subscription","commits_url":"https://api.github.com/repos/zensum/scheduler/commits{/sha}","git_commits_url":"https://api.github.com/repos/zensum/scheduler/git/commits{/sha}","comments_url":"https://api.github.com/repos/zensum/scheduler/comments{/number}","issue_comment_url":"https://api.github.com/repos/zensum/scheduler/issues/comments{/number}","contents_url":"https://api.github.com/repos/zensum/scheduler/contents/{+path}","compare_url":"https://api.github.com/repos/zensum/scheduler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zensum/scheduler/merges","archive_url":"https://api.github.com/repos/zensum/scheduler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zensum/scheduler/downloads","issues_url":"https://api.github.com/repos/zensum/scheduler/issues{/number}","pulls_url":"https://api.github.com/repos/zensum/scheduler/pulls{/number}","milestones_url":"https://api.github.com/repos/zensum/scheduler/milestones{/number}","notifications_url":"https://api.github.com/repos/zensum/scheduler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zensum/scheduler/labels{/name}","releases_url":"https://api.github.com/repos/zensum/scheduler/releases{/id}","deployments_url":"https://api.github.com/repos/zensum/scheduler/deployments","created_at":"2017-10-19T21:50:49Z","updated_at":"2017-10-23T10:36:50Z","pushed_at":"2018-02-06T14:46:08Z","git_url":"git://github.com/zensum/scheduler.git","ssh_url":"git@github.com:zensum/scheduler.git","clone_url":"https://github.com/zensum/scheduler.git","svn_url":"https://github.com/zensum/scheduler","homepage":null,"size":16,"stargazers_count":1,"watchers_count":1,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"zensum:master","ref":"master","sha":"cc6dcb4727b904e99cb2f0346878fd8e5ff08afb","user":{"login":"zensum","id":6458660,"avatar_url":"https://avatars3.githubusercontent.com/u/6458660?v=4","gravatar_id":"","url":"https://api.github.com/users/zensum","html_url":"https://github.com/zensum","followers_url":"https://api.github.com/users/zensum/followers","following_url":"https://api.github.com/users/zensum/following{/other_user}","gists_url":"https://api.github.com/users/zensum/gists{/gist_id}","starred_url":"https://api.github.com/users/zensum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zensum/subscriptions","organizations_url":"https://api.github.com/users/zensum/orgs","repos_url":"https://api.github.com/users/zensum/repos","events_url":"https://api.github.com/users/zensum/events{/privacy}","received_events_url":"https://api.github.com/users/zensum/received_events","type":"Organization","site_admin":false},"repo":{"id":107602473,"name":"scheduler","full_name":"zensum/scheduler","owner":{"login":"zensum","id":6458660,"avatar_url":"https://avatars3.githubusercontent.com/u/6458660?v=4","gravatar_id":"","url":"https://api.github.com/users/zensum","html_url":"https://github.com/zensum","followers_url":"https://api.github.com/users/zensum/followers","following_url":"https://api.github.com/users/zensum/following{/other_user}","gists_url":"https://api.github.com/users/zensum/gists{/gist_id}","starred_url":"https://api.github.com/users/zensum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zensum/subscriptions","organizations_url":"https://api.github.com/users/zensum/orgs","repos_url":"https://api.github.com/users/zensum/repos","events_url":"https://api.github.com/users/zensum/events{/privacy}","received_events_url":"https://api.github.com/users/zensum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zensum/scheduler","description":null,"fork":false,"url":"https://api.github.com/repos/zensum/scheduler","forks_url":"https://api.github.com/repos/zensum/scheduler/forks","keys_url":"https://api.github.com/repos/zensum/scheduler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zensum/scheduler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zensum/scheduler/teams","hooks_url":"https://api.github.com/repos/zensum/scheduler/hooks","issue_events_url":"https://api.github.com/repos/zensum/scheduler/issues/events{/number}","events_url":"https://api.github.com/repos/zensum/scheduler/events","assignees_url":"https://api.github.com/repos/zensum/scheduler/assignees{/user}","branches_url":"https://api.github.com/repos/zensum/scheduler/branches{/branch}","tags_url":"https://api.github.com/repos/zensum/scheduler/tags","blobs_url":"https://api.github.com/repos/zensum/scheduler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zensum/scheduler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zensum/scheduler/git/refs{/sha}","trees_url":"https://api.github.com/repos/zensum/scheduler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zensum/scheduler/statuses/{sha}","languages_url":"https://api.github.com/repos/zensum/scheduler/languages","stargazers_url":"https://api.github.com/repos/zensum/scheduler/stargazers","contributors_url":"https://api.github.com/repos/zensum/scheduler/contributors","subscribers_url":"https://api.github.com/repos/zensum/scheduler/subscribers","subscription_url":"https://api.github.com/repos/zensum/scheduler/subscription","commits_url":"https://api.github.com/repos/zensum/scheduler/commits{/sha}","git_commits_url":"https://api.github.com/repos/zensum/scheduler/git/commits{/sha}","comments_url":"https://api.github.com/repos/zensum/scheduler/comments{/number}","issue_comment_url":"https://api.github.com/repos/zensum/scheduler/issues/comments{/number}","contents_url":"https://api.github.com/repos/zensum/scheduler/contents/{+path}","compare_url":"https://api.github.com/repos/zensum/scheduler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zensum/scheduler/merges","archive_url":"https://api.github.com/repos/zensum/scheduler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zensum/scheduler/downloads","issues_url":"https://api.github.com/repos/zensum/scheduler/issues{/number}","pulls_url":"https://api.github.com/repos/zensum/scheduler/pulls{/number}","milestones_url":"https://api.github.com/repos/zensum/scheduler/milestones{/number}","notifications_url":"https://api.github.com/repos/zensum/scheduler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zensum/scheduler/labels{/name}","releases_url":"https://api.github.com/repos/zensum/scheduler/releases{/id}","deployments_url":"https://api.github.com/repos/zensum/scheduler/deployments","created_at":"2017-10-19T21:50:49Z","updated_at":"2017-10-23T10:36:50Z","pushed_at":"2018-02-06T14:46:08Z","git_url":"git://github.com/zensum/scheduler.git","ssh_url":"git@github.com:zensum/scheduler.git","clone_url":"https://github.com/zensum/scheduler.git","svn_url":"https://github.com/zensum/scheduler","homepage":null,"size":16,"stargazers_count":1,"watchers_count":1,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/1"},"html":{"href":"https://github.com/zensum/scheduler/pull/1"},"issue":{"href":"https://api.github.com/repos/zensum/scheduler/issues/1"},"comments":{"href":"https://api.github.com/repos/zensum/scheduler/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zensum/scheduler/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/zensum/scheduler/statuses/7fc8497175f94fd823ecf79434fe987abeb25098"}},"author_association":"NONE"}}
{"actor":{"display_login":"williamhogman"}}