{"action":"created","comment":{"url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/comments/115510634","pull_request_review_id":37054107,"id":115510634,"diff_hunk":"@@ -0,0 +1,133 @@\n+/**\n+ * Copyright 2009-2017 the original author or authors.\n+ * <p>\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ * <p>\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ * <p>\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package net.javacrumbs.shedlock.provider.jedis;\n+\n+import net.javacrumbs.shedlock.core.LockConfiguration;\n+import net.javacrumbs.shedlock.core.LockProvider;\n+import net.javacrumbs.shedlock.core.SimpleLock;\n+import net.javacrumbs.shedlock.support.LockException;\n+import redis.clients.jedis.Jedis;\n+import redis.clients.jedis.JedisPool;\n+\n+import java.net.InetAddress;\n+import java.net.UnknownHostException;\n+import java.time.Duration;\n+import java.time.Instant;\n+import java.time.temporal.ChronoUnit;\n+import java.util.Optional;\n+\n+/**\n+ * Uses Redis's `SET resource-name anystring NX PX max-lock-ms-time` as locking mechanism.\n+ *\n+ * See https://redis.io/commands/set\n+ *\n+ */\n+public class JedisLockProvider implements LockProvider {\n+\n+    private static final String KEY_PREFIX = \"job-lock\";\n+    private static final String ENV_DEFAULT = \"default\";\n+\n+    private static final long AT_MOST_HOURS_DEFAULT = 1;\n+\n+    // Redis Flags\n+    private static final String SET_IF_NOT_EXIST = \"NX\";\n+    private static final String SET_EXPIRE_TIME_IN_MS = \"PX\";\n+\n+    private JedisPool jedisPool;\n+    private String environment;\n+    private Duration atMostHoursDefault;\n+\n+    public JedisLockProvider(JedisPool jedisPool) {\n+        this(jedisPool, ENV_DEFAULT, AT_MOST_HOURS_DEFAULT);\n+    }\n+\n+    public JedisLockProvider(JedisPool jedisPool, String environment) {\n+        this(jedisPool, environment, AT_MOST_HOURS_DEFAULT);\n+    }\n+\n+    public JedisLockProvider(JedisPool jedisPool, String environment, long atMostHoursDefault) {\n+        this.jedisPool = jedisPool;\n+        this.environment = environment;\n+        this.atMostHoursDefault = Duration.of(atMostHoursDefault, ChronoUnit.HOURS);\n+    }\n+\n+    @Override\n+    public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {\n+        Instant now = Instant.now();\n+\n+        // Get 'furthest out' configured expire time for lock TTL\n+        long expireTime = Math.max(\n+            Duration.between(now, lockConfiguration.getLockAtMostUntil()).toMillis(),","path":"shedlock-provider-jedis/src/main/java/net/javacrumbs/shedlock/provider/jedis/JedisLockProvider.java","position":73,"original_position":73,"commit_id":"f8706cc393eb6c2a1a9ddb21fc7b5ea4d155a236","original_commit_id":"f8706cc393eb6c2a1a9ddb21fc7b5ea4d155a236","user":{"login":"clamey","id":1063046,"avatar_url":"https://avatars3.githubusercontent.com/u/1063046?v=3","gravatar_id":"","url":"https://api.github.com/users/clamey","html_url":"https://github.com/clamey","followers_url":"https://api.github.com/users/clamey/followers","following_url":"https://api.github.com/users/clamey/following{/other_user}","gists_url":"https://api.github.com/users/clamey/gists{/gist_id}","starred_url":"https://api.github.com/users/clamey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clamey/subscriptions","organizations_url":"https://api.github.com/users/clamey/orgs","repos_url":"https://api.github.com/users/clamey/repos","events_url":"https://api.github.com/users/clamey/events{/privacy}","received_events_url":"https://api.github.com/users/clamey/received_events","type":"User","site_admin":false},"body":"Sounds good","created_at":"2017-05-09T14:53:11Z","updated_at":"2017-05-09T14:53:11Z","html_url":"https://github.com/lukas-krecan/ShedLock/pull/18#discussion_r115510634","pull_request_url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/comments/115510634"},"html":{"href":"https://github.com/lukas-krecan/ShedLock/pull/18#discussion_r115510634"},"pull_request":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18","id":119491919,"html_url":"https://github.com/lukas-krecan/ShedLock/pull/18","diff_url":"https://github.com/lukas-krecan/ShedLock/pull/18.diff","patch_url":"https://github.com/lukas-krecan/ShedLock/pull/18.patch","issue_url":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/18","number":18,"state":"open","locked":false,"title":"Added Jedis as provider","user":{"login":"clamey","id":1063046,"avatar_url":"https://avatars3.githubusercontent.com/u/1063046?v=3","gravatar_id":"","url":"https://api.github.com/users/clamey","html_url":"https://github.com/clamey","followers_url":"https://api.github.com/users/clamey/followers","following_url":"https://api.github.com/users/clamey/following{/other_user}","gists_url":"https://api.github.com/users/clamey/gists{/gist_id}","starred_url":"https://api.github.com/users/clamey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clamey/subscriptions","organizations_url":"https://api.github.com/users/clamey/orgs","repos_url":"https://api.github.com/users/clamey/repos","events_url":"https://api.github.com/users/clamey/events{/privacy}","received_events_url":"https://api.github.com/users/clamey/received_events","type":"User","site_admin":false},"body":"Here's an attempt at using Redis as a lock provider with Jedis as the client.  Sadly, there is no decent embeddable Redis instance for testing, so in order to run the JedisLockProviderIntegrationTest you'll need Redis installed locally.  Because of this, I've disabled the shedlock-provider-jedis tests for now so it's not required for ShedLock overall.  The general opinion from the Jedis/Redis world is to have a Redis instance run on your CI box, but I'm not sure that's something you want for the ShedLock TravisCI.\r\n\r\nFYI, I tried using the spring-data-redis RedisTemplate instead of Jedis, but that client doesn't support the putIfAbsent with an expiration and evaluate a return semantics that I'd like to use.  Plus the Jedis client interface is much more Redis-like and easier to use that the Spring RedisTemplate.","created_at":"2017-05-08T17:07:18Z","updated_at":"2017-05-09T14:53:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49880bbb4a48c555a8a9fb276e0ca75709cb1349","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18/commits","review_comments_url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18/comments","review_comment_url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/18/comments","statuses_url":"https://api.github.com/repos/lukas-krecan/ShedLock/statuses/f8706cc393eb6c2a1a9ddb21fc7b5ea4d155a236","head":{"label":"clamey:master","ref":"master","sha":"f8706cc393eb6c2a1a9ddb21fc7b5ea4d155a236","user":{"login":"clamey","id":1063046,"avatar_url":"https://avatars3.githubusercontent.com/u/1063046?v=3","gravatar_id":"","url":"https://api.github.com/users/clamey","html_url":"https://github.com/clamey","followers_url":"https://api.github.com/users/clamey/followers","following_url":"https://api.github.com/users/clamey/following{/other_user}","gists_url":"https://api.github.com/users/clamey/gists{/gist_id}","starred_url":"https://api.github.com/users/clamey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clamey/subscriptions","organizations_url":"https://api.github.com/users/clamey/orgs","repos_url":"https://api.github.com/users/clamey/repos","events_url":"https://api.github.com/users/clamey/events{/privacy}","received_events_url":"https://api.github.com/users/clamey/received_events","type":"User","site_admin":false},"repo":{"id":90191717,"name":"ShedLock","full_name":"clamey/ShedLock","owner":{"login":"clamey","id":1063046,"avatar_url":"https://avatars3.githubusercontent.com/u/1063046?v=3","gravatar_id":"","url":"https://api.github.com/users/clamey","html_url":"https://github.com/clamey","followers_url":"https://api.github.com/users/clamey/followers","following_url":"https://api.github.com/users/clamey/following{/other_user}","gists_url":"https://api.github.com/users/clamey/gists{/gist_id}","starred_url":"https://api.github.com/users/clamey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clamey/subscriptions","organizations_url":"https://api.github.com/users/clamey/orgs","repos_url":"https://api.github.com/users/clamey/repos","events_url":"https://api.github.com/users/clamey/events{/privacy}","received_events_url":"https://api.github.com/users/clamey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/clamey/ShedLock","description":"Distributed lock for your scheduled tasks","fork":true,"url":"https://api.github.com/repos/clamey/ShedLock","forks_url":"https://api.github.com/repos/clamey/ShedLock/forks","keys_url":"https://api.github.com/repos/clamey/ShedLock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/clamey/ShedLock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/clamey/ShedLock/teams","hooks_url":"https://api.github.com/repos/clamey/ShedLock/hooks","issue_events_url":"https://api.github.com/repos/clamey/ShedLock/issues/events{/number}","events_url":"https://api.github.com/repos/clamey/ShedLock/events","assignees_url":"https://api.github.com/repos/clamey/ShedLock/assignees{/user}","branches_url":"https://api.github.com/repos/clamey/ShedLock/branches{/branch}","tags_url":"https://api.github.com/repos/clamey/ShedLock/tags","blobs_url":"https://api.github.com/repos/clamey/ShedLock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/clamey/ShedLock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/clamey/ShedLock/git/refs{/sha}","trees_url":"https://api.github.com/repos/clamey/ShedLock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/clamey/ShedLock/statuses/{sha}","languages_url":"https://api.github.com/repos/clamey/ShedLock/languages","stargazers_url":"https://api.github.com/repos/clamey/ShedLock/stargazers","contributors_url":"https://api.github.com/repos/clamey/ShedLock/contributors","subscribers_url":"https://api.github.com/repos/clamey/ShedLock/subscribers","subscription_url":"https://api.github.com/repos/clamey/ShedLock/subscription","commits_url":"https://api.github.com/repos/clamey/ShedLock/commits{/sha}","git_commits_url":"https://api.github.com/repos/clamey/ShedLock/git/commits{/sha}","comments_url":"https://api.github.com/repos/clamey/ShedLock/comments{/number}","issue_comment_url":"https://api.github.com/repos/clamey/ShedLock/issues/comments{/number}","contents_url":"https://api.github.com/repos/clamey/ShedLock/contents/{+path}","compare_url":"https://api.github.com/repos/clamey/ShedLock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/clamey/ShedLock/merges","archive_url":"https://api.github.com/repos/clamey/ShedLock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/clamey/ShedLock/downloads","issues_url":"https://api.github.com/repos/clamey/ShedLock/issues{/number}","pulls_url":"https://api.github.com/repos/clamey/ShedLock/pulls{/number}","milestones_url":"https://api.github.com/repos/clamey/ShedLock/milestones{/number}","notifications_url":"https://api.github.com/repos/clamey/ShedLock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/clamey/ShedLock/labels{/name}","releases_url":"https://api.github.com/repos/clamey/ShedLock/releases{/id}","deployments_url":"https://api.github.com/repos/clamey/ShedLock/deployments","created_at":"2017-05-03T20:43:15Z","updated_at":"2017-05-03T20:43:16Z","pushed_at":"2017-05-08T22:54:12Z","git_url":"git://github.com/clamey/ShedLock.git","ssh_url":"git@github.com:clamey/ShedLock.git","clone_url":"https://github.com/clamey/ShedLock.git","svn_url":"https://github.com/clamey/ShedLock","homepage":"","size":257,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"lukas-krecan:master","ref":"master","sha":"9e6ae6df63c02f7ffa3289c008a8278b1af3e0af","user":{"login":"lukas-krecan","id":815787,"avatar_url":"https://avatars0.githubusercontent.com/u/815787?v=3","gravatar_id":"","url":"https://api.github.com/users/lukas-krecan","html_url":"https://github.com/lukas-krecan","followers_url":"https://api.github.com/users/lukas-krecan/followers","following_url":"https://api.github.com/users/lukas-krecan/following{/other_user}","gists_url":"https://api.github.com/users/lukas-krecan/gists{/gist_id}","starred_url":"https://api.github.com/users/lukas-krecan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukas-krecan/subscriptions","organizations_url":"https://api.github.com/users/lukas-krecan/orgs","repos_url":"https://api.github.com/users/lukas-krecan/repos","events_url":"https://api.github.com/users/lukas-krecan/events{/privacy}","received_events_url":"https://api.github.com/users/lukas-krecan/received_events","type":"User","site_admin":false},"repo":{"id":76177416,"name":"ShedLock","full_name":"lukas-krecan/ShedLock","owner":{"login":"lukas-krecan","id":815787,"avatar_url":"https://avatars0.githubusercontent.com/u/815787?v=3","gravatar_id":"","url":"https://api.github.com/users/lukas-krecan","html_url":"https://github.com/lukas-krecan","followers_url":"https://api.github.com/users/lukas-krecan/followers","following_url":"https://api.github.com/users/lukas-krecan/following{/other_user}","gists_url":"https://api.github.com/users/lukas-krecan/gists{/gist_id}","starred_url":"https://api.github.com/users/lukas-krecan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukas-krecan/subscriptions","organizations_url":"https://api.github.com/users/lukas-krecan/orgs","repos_url":"https://api.github.com/users/lukas-krecan/repos","events_url":"https://api.github.com/users/lukas-krecan/events{/privacy}","received_events_url":"https://api.github.com/users/lukas-krecan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lukas-krecan/ShedLock","description":"Distributed lock for your scheduled tasks","fork":false,"url":"https://api.github.com/repos/lukas-krecan/ShedLock","forks_url":"https://api.github.com/repos/lukas-krecan/ShedLock/forks","keys_url":"https://api.github.com/repos/lukas-krecan/ShedLock/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lukas-krecan/ShedLock/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lukas-krecan/ShedLock/teams","hooks_url":"https://api.github.com/repos/lukas-krecan/ShedLock/hooks","issue_events_url":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/events{/number}","events_url":"https://api.github.com/repos/lukas-krecan/ShedLock/events","assignees_url":"https://api.github.com/repos/lukas-krecan/ShedLock/assignees{/user}","branches_url":"https://api.github.com/repos/lukas-krecan/ShedLock/branches{/branch}","tags_url":"https://api.github.com/repos/lukas-krecan/ShedLock/tags","blobs_url":"https://api.github.com/repos/lukas-krecan/ShedLock/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lukas-krecan/ShedLock/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lukas-krecan/ShedLock/git/refs{/sha}","trees_url":"https://api.github.com/repos/lukas-krecan/ShedLock/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lukas-krecan/ShedLock/statuses/{sha}","languages_url":"https://api.github.com/repos/lukas-krecan/ShedLock/languages","stargazers_url":"https://api.github.com/repos/lukas-krecan/ShedLock/stargazers","contributors_url":"https://api.github.com/repos/lukas-krecan/ShedLock/contributors","subscribers_url":"https://api.github.com/repos/lukas-krecan/ShedLock/subscribers","subscription_url":"https://api.github.com/repos/lukas-krecan/ShedLock/subscription","commits_url":"https://api.github.com/repos/lukas-krecan/ShedLock/commits{/sha}","git_commits_url":"https://api.github.com/repos/lukas-krecan/ShedLock/git/commits{/sha}","comments_url":"https://api.github.com/repos/lukas-krecan/ShedLock/comments{/number}","issue_comment_url":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/comments{/number}","contents_url":"https://api.github.com/repos/lukas-krecan/ShedLock/contents/{+path}","compare_url":"https://api.github.com/repos/lukas-krecan/ShedLock/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lukas-krecan/ShedLock/merges","archive_url":"https://api.github.com/repos/lukas-krecan/ShedLock/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lukas-krecan/ShedLock/downloads","issues_url":"https://api.github.com/repos/lukas-krecan/ShedLock/issues{/number}","pulls_url":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls{/number}","milestones_url":"https://api.github.com/repos/lukas-krecan/ShedLock/milestones{/number}","notifications_url":"https://api.github.com/repos/lukas-krecan/ShedLock/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lukas-krecan/ShedLock/labels{/name}","releases_url":"https://api.github.com/repos/lukas-krecan/ShedLock/releases{/id}","deployments_url":"https://api.github.com/repos/lukas-krecan/ShedLock/deployments","created_at":"2016-12-11T13:53:59Z","updated_at":"2017-04-28T05:38:29Z","pushed_at":"2017-05-09T05:48:44Z","git_url":"git://github.com/lukas-krecan/ShedLock.git","ssh_url":"git@github.com:lukas-krecan/ShedLock.git","clone_url":"https://github.com/lukas-krecan/ShedLock.git","svn_url":"https://github.com/lukas-krecan/ShedLock","homepage":"","size":252,"stargazers_count":39,"watchers_count":39,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":3,"forks":10,"open_issues":3,"watchers":39,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18"},"html":{"href":"https://github.com/lukas-krecan/ShedLock/pull/18"},"issue":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/18"},"comments":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/lukas-krecan/ShedLock/statuses/f8706cc393eb6c2a1a9ddb21fc7b5ea4d155a236"}}}}
{"actor":{"display_login":"clamey"}}