Repository: kagkarlsson/db-scheduler (java)

Issue:
Adding ofMillis to FixedDelay class
It would be useful to add a shorthand for fixed delay ofMillis much like we have for minutes, etc.

I'm happy to open a pr?

Thanks,
Des


Discussion:
Sure, go ahead :)

I expect you know that the `FixedDelay` of a task should be at least `pollingInterval` of the Scheduler.

Patch:
diff --git a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelay.java b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelay.java
--- a/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelay.java
+++ b/db-scheduler/src/main/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelay.java
@@ -33,6 +33,11 @@ public static FixedDelay of(Duration duration) {
         return new FixedDelay(duration);
     }
 
+    public static FixedDelay ofMillis(long millis) {
+        validateDuration(millis);
+        return new FixedDelay(Duration.ofMillis(millis));
+    }
+
     public static FixedDelay ofSeconds(int seconds) {
         validateDuration(seconds);
         return new FixedDelay(Duration.ofSeconds(seconds));
@@ -48,7 +53,7 @@ public static FixedDelay ofHours(int hours) {
         return new FixedDelay(Duration.ofHours(hours));
     }
 
-    private static void validateDuration(int seconds) {
+    private static void validateDuration(long seconds) {
         if (seconds <= 0) {
             throw new IllegalArgumentException("argument must be greater than 0");
         }


Test patch:
diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/CompatibilityTest.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/CompatibilityTest.java
--- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/CompatibilityTest.java
+++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/compatibility/CompatibilityTest.java
@@ -68,8 +68,8 @@ public void setUp() {
         delayingHandlerRecurring = new TestTasks.CountingHandler<>(Duration.ofMillis(200));
 
         oneTime = TestTasks.oneTimeWithType("oneTime", String.class, delayingHandlerOneTime);
-        recurring = TestTasks.recurring("recurring", FixedDelay.of(Duration.ofMillis(10)), delayingHandlerRecurring);
-        recurringWithData = TestTasks.recurringWithData("recurringWithData", Integer.class, 0, FixedDelay.of(Duration.ofMillis(10)), new DoNothingHandler<>());
+        recurring = TestTasks.recurring("recurring", FixedDelay.ofMillis(10), delayingHandlerRecurring);
+        recurringWithData = TestTasks.recurringWithData("recurringWithData", Integer.class, 0, FixedDelay.ofMillis(10), new DoNothingHandler<>());
 
         completed12Condition = new ExecutionCompletedCondition(12);
         testableRegistry = new TestableRegistry(false, singletonList(completed12Condition));
diff --git a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelayTest.java b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelayTest.java
--- a/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelayTest.java
+++ b/db-scheduler/src/test/java/com/github/kagkarlsson/scheduler/task/schedule/FixedDelayTest.java
@@ -15,6 +15,9 @@ public void equals_and_hash_code() {
 
     @Test
     public void to_string() {
-        assertEquals("FixedDelay duration=PT2M", FixedDelay.of(Duration.ofMinutes(2)).toString());
+        assertEquals("FixedDelay duration=PT1.5S", FixedDelay.ofMillis(1500).toString());
+        assertEquals("FixedDelay duration=PT3S", FixedDelay.ofSeconds(3).toString());
+        assertEquals("FixedDelay duration=PT6M", FixedDelay.ofMinutes(6).toString());
+        assertEquals("FixedDelay duration=PT12H", FixedDelay.ofHours(12).toString());
     }
 }