-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: reject zero and negative periodic tasks schedule #887
Changes from 1 commit
0e0a31f
12f1038
d261148
8683ea1
30a40ab
b4530f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,12 +105,14 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac | |
|
||
override def scheduleWithFixedDelay(initialDelay: FiniteDuration, delay: FiniteDuration)(runnable: Runnable)( | ||
implicit executor: ExecutionContext): Cancellable = { | ||
checkZeroPeriod(delay.toNanos) | ||
checkMaxDelay(roundUp(delay).toNanos) | ||
super.scheduleWithFixedDelay(initialDelay, delay)(runnable) | ||
} | ||
|
||
override def schedule(initialDelay: FiniteDuration, delay: FiniteDuration, runnable: Runnable)( | ||
implicit executor: ExecutionContext): Cancellable = { | ||
checkZeroPeriod(delay.toNanos) | ||
Roiocam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
checkMaxDelay(roundUp(delay).toNanos) | ||
new AtomicCancellable(InitialRepeatMarker) { self => | ||
final override protected def scheduledFirst(): Cancellable = | ||
|
@@ -200,6 +202,11 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac | |
s"Task scheduled with [${delayNanos.nanos.toSeconds}] seconds delay, " + | ||
s"which is too far in future, maximum delay is [${(tickNanos * Int.MaxValue).nanos.toSeconds - 1}] seconds") | ||
|
||
private def checkZeroPeriod(delayNanos: Long): Unit = | ||
if (delayNanos <= 0) | ||
throw new IllegalArgumentException( | ||
"Task scheduled with zero or negative period, which is create an an infinite loop") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use:
user do not know what's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about "Task scheduled with [${delay.toSeconds}] seconds delay, which means creating an infinite loop. The expected delay must be greater than 0."? |
||
|
||
private val stopped = new AtomicReference[Promise[immutable.Seq[TimerTask]]] | ||
private def stop(): Future[immutable.Seq[TimerTask]] = { | ||
val p = Promise[immutable.Seq[TimerTask]]() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the printlns