Process time series data

Updated at:

A scheduled job sometimes needs to process data from a different time window than when it actually runs. For example, a job triggered at 00:30 might need to process data from 23:30 the previous day. SchedulerX solves this through a time offset that decouples execution time from data time, so you can schedule jobs based on operational convenience while targeting the correct data window.

How time offset works

Every SchedulerX job has two timestamps:

  • Execution time: When the job is triggered (for example, 00:30 daily).

  • Data time: The timestamp passed to your code through context.getDataTime(). By default, data time equals execution time.

Set a negative time offset to shift the data time backward. The offset is specified in seconds.

Execution time Time offset Data time
2024-01-02 00:30 0 (default) 2024-01-02 00:30
2024-01-02 00:30 -3600 (1 hour) 2024-01-01 23:30
2024-01-02 00:30 -7200 (2 hours) 2024-01-01 22:30
2024-01-02 00:30 -86400 (24 hours) 2024-01-01 00:30

The time offset only affects the value returned by context.getDataTime(). It does not change when the job is triggered.

Retrieve the data time in your job

Before you begin, make sure you have a SchedulerX agent connected to your application. For setup instructions, see the Quick start topic.

Call context.getDataTime() in your job processor to retrieve the adjusted data time. This method returns the execution time shifted by the configured offset.

public class TestHelloJob extends JavaProcessor {

    @Override
    public ProcessResult process(JobContext context) throws Exception {
        System.out.println("hello schedulerx2.0");

        // Retrieve the data time (execution time minus the configured offset)
        System.out.println("dataTime=" + context.getDataTime().toString("yyyy-MM-dd HH:mm:ss"));

        return new ProcessResult(true);
    }

}

Configure the time offset in the console

  1. Log in to the SchedulerX console.

  2. Create a job.

  3. On the Timing configuration wizard page, set Time offset to -3600. The unit is seconds, so -3600 shifts the data time back by 1 hour.

The job still triggers at its scheduled time (for example, 00:30). When the job runs, context.getDataTime() returns 23:30 on the previous day instead of 00:30.

Verify that the data time offset is applied

  1. Go to the Instances page and find the job instance.

  2. Click Details in the Operation column.

  3. On the Job Instance Details page, click Basic Information.

  4. Confirm that Data Time shows the expected offset time, not the execution time.