Date Ranges Processing

Usually trigger configuration contains a field Monitor from date with the following requirements:

  • Workflow should only process updates made on this specified date and further on
  • If this date is changed to the older one, the previously processed objects shouldn’t be reprocessed.
    • Workflow should process only newest updates and those created in the period [new_date; old_date)

The above statements assume that the target API contains information about object creation and(or) last modification date. If such information is not available, see No Date Ranges section below.

In order to satisfy the above requirements the following algorithm must be implemented:

IF NOT(input.meta.origMonitorFromDate) OR input.conditions.monitorFromDate > input.meta.processFromDate 
    DOWNLOAD UPDATES IN RANGE [input.conditions.monitorFromDate; ∞)
ELSE IF input.conditions.monitorFromDate < input.meta.origMonitorFromDate
    DOWNLOAD UPDATES IN RANGE [input.conditions.monitorFromDate; input.meta.origMonitorFromDate)
    DOWNLOAD UPDATES IN RANGE [input.meta.processFromDate; ∞)
ELSE IF 
    DOWNLOAD UPDATES IN RANGE [input.meta.processFromDate; ∞)
END IF

output.meta.origMonitorFromDate = input.conditions.monitorFromDate
output.meta.processFromDate = Max(TRANSACTIONS.UPDATED)

It saves only 2 fields in the trigger metadata (origMonitorFromDate, processFromDate), but satisfies the above requirements and does not use a lot of storage to keep a list of previously processed transactions.

The algorithm is already implemented here:

No Date Ranges (Processed ID’s Persistence)

When entities do not have creation/update timestamps and entity ID’s are not sequential, the only way to retrieve new updates only is to keep a list of already processed entity ID’s.

In a such case, a separate DB must be used. MongoDB is the default choice.