Skip to content

Commit

Permalink
Use relative time(duration) for timer instead of absolute (firingUnix…
Browse files Browse the repository at this point in the history
…TimestampSeconds)
  • Loading branch information
longquanzheng committed May 20, 2024
1 parent f11512a commit e64909d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion iwf-idl
6 changes: 3 additions & 3 deletions src/main/java/io/iworkflow/core/command/TimerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
@Value.Immutable
public abstract class TimerCommand implements BaseCommand {

public abstract int getFiringUnixTimestampSeconds();
public abstract int getDurationSeconds();

public static TimerCommand createByDuration(String commandId, Duration duration) {
return ImmutableTimerCommand.builder()
.commandId(commandId)
.firingUnixTimestampSeconds((int) (System.currentTimeMillis() / 1000 + duration.getSeconds()))
.durationSeconds((int) duration.getSeconds())
.build();
}

public static TimerCommand createByDuration(Duration duration) {
return ImmutableTimerCommand.builder()
.firingUnixTimestampSeconds((int) (System.currentTimeMillis() / 1000 + duration.getSeconds()))
.durationSeconds((int) duration.getSeconds())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class TimerCommandMapper {
public static TimerCommand toGenerated(io.iworkflow.core.command.TimerCommand timerCommand) {
final TimerCommand command = new TimerCommand()
.firingUnixTimestampSeconds((long) timerCommand.getFiringUnixTimestampSeconds());
.durationSeconds( timerCommand.getDurationSeconds());
if (timerCommand.getCommandId().isPresent()) {
command.commandId(timerCommand.getCommandId().get());
}
Expand Down

0 comments on commit e64909d

Please sign in to comment.