Skip to content

Commit

Permalink
Allow override to always UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
kagkarlsson committed Jan 30, 2024
1 parent 64c18e3 commit dacb5fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public Scheduler scheduler(DbSchedulerCustomizer customizer, StatsRegistry regis
.jdbcCustomization()
.orElse(new AutodetectJdbcCustomization(transactionalDataSource)));

if (config.isAlwaysPersistTimestampInUtc()) {
builder.alwaysPersistTimestampInUTC();
}

if (config.isImmediateExecutionEnabled()) {
builder.enableImmediateExecution();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public class DbSchedulerProperties {
@DurationUnit(SECONDS)
private Duration shutdownMaxWait = SchedulerBuilder.SHUTDOWN_MAX_WAIT;

/**
* Store timestamps in UTC timezone even though the schema supports storing timezone information
*/
private boolean alwaysPersistTimestampInUtc = false;

/** Which log level to use when logging task failures. Defaults to {@link LogLevel#DEBUG}. */
private LogLevel failureLoggerLevel = SchedulerBuilder.DEFAULT_FAILURE_LOG_LEVEL;

Expand Down Expand Up @@ -228,4 +233,12 @@ public void setPollingStrategyUpperLimitFractionOfThreads(
double pollingStrategyUpperLimitFractionOfThreads) {
this.pollingStrategyUpperLimitFractionOfThreads = pollingStrategyUpperLimitFractionOfThreads;
}

public boolean isAlwaysPersistTimestampInUtc() {
return alwaysPersistTimestampInUtc;
}

public void setAlwaysPersistTimestampInUtc(boolean alwaysPersistTimestampInUTC) {
this.alwaysPersistTimestampInUtc = alwaysPersistTimestampInUTC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SchedulerBuilder {
protected LogLevel logLevel = DEFAULT_FAILURE_LOG_LEVEL;
protected boolean logStackTrace = LOG_STACK_TRACE_ON_FAILURE;
private boolean registerShutdownHook = false;
private boolean alwaysPersistTimestampInUTC = false;

public SchedulerBuilder(DataSource dataSource, List<Task<?>> knownTasks) {
this.dataSource = dataSource;
Expand Down Expand Up @@ -156,6 +157,11 @@ public SchedulerBuilder jdbcCustomization(JdbcCustomization jdbcCustomization) {
return this;
}

public SchedulerBuilder alwaysPersistTimestampInUTC() {
this.alwaysPersistTimestampInUTC = true;
return this;
}

public SchedulerBuilder shutdownMaxWait(Duration shutdownMaxWait) {
this.shutdownMaxWait = shutdownMaxWait;
return this;
Expand Down Expand Up @@ -208,7 +214,7 @@ public Scheduler build() {
final TaskResolver taskResolver = new TaskResolver(statsRegistry, clock, knownTasks);
final JdbcCustomization jdbcCustomization =
ofNullable(this.jdbcCustomization)
.orElseGet(() -> new AutodetectJdbcCustomization(dataSource));
.orElseGet(() -> new AutodetectJdbcCustomization(dataSource, alwaysPersistTimestampInUTC));
final JdbcTaskRepository schedulerTaskRepository =
new JdbcTaskRepository(
dataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ db-scheduler.polling-strategy=fetch
db-scheduler.polling-strategy-lower-limit-fraction-of-threads=0.5
db-scheduler.polling-strategy-upper-limit-fraction-of-threads=3.0
db-scheduler.shutdown-max-wait=30m
db-scheduler.always-persist-timestamp-in-utc=false

0 comments on commit dacb5fd

Please sign in to comment.