code: private void generateWork() {
          List<DataSource> tables = db().getAllDataSources();
          long now = System.currentTimeMillis();
          List<List<StatusTrail>> stPerDataSource = new ArrayList<>();
          for (DataSource ds:tables) {
              if (ds.getStatus() == null) {
                  log.error("DataSource {}'s status is null", ds);
                  continue;
              }
              if (JobStatus.valueOf(ds.getStatus()) == JobStatus.done) {                
                  continue;
              }
              long currentSpinOffTime = ds.getSpinFromTime();            
              //If startTime = spinOffTime = 00 hr. If now = getTaskAttemptDelay() + 03 hr, and job is hourly job then
              // The following will materialize 00, 01, 02 , 03 adds them to StatusTrail, updates the spinnOff Time to 03.
              // NOTE: All the above times should be within endTime.
              while (now > (currentSpinOffTime + getTaskAttemptDelayInMillis()) && currentSpinOffTime < ds.getEndTime()) {                                
                  StatusTrail st = new StatusTrail().setNominalTime(currentSpinOffTime).
                          setAttemptsDone(0).
                          setDataSourceId(ds.getId()).
                          setGivenUp(0).
                          setStatus(JobStatus.not_done);
                  db().addStatusTrail(st);
                  currentSpinOffTime += JobFreq.valueOf(ds.getFrequency()).inMillis();
                  log.info("Generated work : {}", st);
              }
              if (currentSpinOffTime > ds.getEndTime()) {
                  ds.setStatus(JobStatus.done);
              }
              stPerDataSource.add(db().getIncompleteTasks(ds));
              //Update the spinOff Time to point to time from which next set of materialization will happen.
              db().updateDataSource(ds.setSpinFromTime(currentSpinOffTime));
          }
          newWorkQueue.clearAndMergeKLists(stPerDataSource);
      }
docs: Generate a bunch of jobs(StatusTrail ready to be run in near future).