diff --git a/redisson/src/main/java/org/redisson/executor/TasksRunnerService.java b/redisson/src/main/java/org/redisson/executor/TasksRunnerService.java
index a5e5c575f..5b3492432 100644
--- a/redisson/src/main/java/org/redisson/executor/TasksRunnerService.java
+++ b/redisson/src/main/java/org/redisson/executor/TasksRunnerService.java
@@ -146,7 +146,7 @@ public class TasksRunnerService implements RemoteExecutorService {
future = service.schedule(params);
}
try {
- executeRunnable(params);
+ executeRunnable(params, nextStartDate);
} catch (RuntimeException e) {
// cancel task if it throws an exception
if (future != null) {
@@ -209,7 +209,7 @@ public class TasksRunnerService implements RemoteExecutorService {
} catch (Exception e) {
throw new IllegalArgumentException(e);
} finally {
- finish(params.getRequestId());
+ finish(params.getRequestId(), null);
}
}
@@ -293,8 +293,7 @@ public class TasksRunnerService implements RemoteExecutorService {
}
}
- @Override
- public void executeRunnable(TaskParameters params) {
+ public void executeRunnable(TaskParameters params, Date nextDate) {
if (params.getRequestId() != null && params.getRequestId().startsWith("00")) {
renewRetryTime(params.getRequestId());
}
@@ -309,9 +308,14 @@ public class TasksRunnerService implements RemoteExecutorService {
} catch (Exception e) {
throw new IllegalArgumentException(e);
} finally {
- finish(params.getRequestId());
+ finish(params.getRequestId(), nextDate);
}
}
+
+ @Override
+ public void executeRunnable(TaskParameters params) {
+ executeRunnable(params, null);
+ }
/**
* Check shutdown state. If tasksCounter equals 0
@@ -323,22 +327,26 @@ public class TasksRunnerService implements RemoteExecutorService {
*
* @param requestId
*/
- private void finish(String requestId) {
+ private void finish(String requestId, Date nextDate) {
+ String script = "";
+ if (nextDate == null) {
+ script += "local scheduled = redis.call('zscore', KEYS[5], ARGV[3]);"
+ + "if scheduled == false then "
+ + "redis.call('hdel', KEYS[4], ARGV[3]); "
+ + "end;";
+ }
+ script += "redis.call('zrem', KEYS[5], 'ff' .. ARGV[3]);" +
+ "if redis.call('decr', KEYS[1]) == 0 then "
+ + "redis.call('del', KEYS[1]);"
+ + "if redis.call('get', KEYS[2]) == ARGV[1] then "
+ + "redis.call('del', KEYS[6]);"
+ + "redis.call('set', KEYS[2], ARGV[2]);"
+ + "redis.call('publish', KEYS[3], ARGV[2]);"
+ + "end;"
+ + "end;";
+
commandExecutor.evalWriteAsync(name, StringCodec.INSTANCE, RedisCommands.EVAL_VOID,
- "local scheduled = redis.call('zscore', KEYS[5], ARGV[3]);"
- + "if scheduled == false then "
- + "redis.call('hdel', KEYS[4], ARGV[3]); "
- + "end;" +
-
- "redis.call('zrem', KEYS[5], 'ff' .. ARGV[3]);" +
- "if redis.call('decr', KEYS[1]) == 0 then "
- + "redis.call('del', KEYS[1]);"
- + "if redis.call('get', KEYS[2]) == ARGV[1] then "
- + "redis.call('del', KEYS[6]);"
- + "redis.call('set', KEYS[2], ARGV[2]);"
- + "redis.call('publish', KEYS[3], ARGV[2]);"
- + "end;"
- + "end;",
+ script,
Arrays.