Timestamp in milliseconds

For an API destination I’m using, they require a “sequence” of records submitted. They suggest this sequence could for instance be the timestamp in milliseconds.

When developing your Import API script, you’ll need to define how values for the sequence property are generated. A simple solution is just to use the current timestamp, but before doing so, consider the following:

How frequently are the records being updated?

If records with identical Primary Key values are updated every few milliseconds and pushed simultaneously, the correct version of a record may not be loaded successfully. This means that records with the same Primary Key values can’t be sent during the same clock resolution. For example: If the resolution is measured in milliseconds, records with identical Primary Key values cannot be sent during the same millisecond.

I could only find the timestamp in seconds in Wappler, not milliseconds. Is this available somehow? Or do you maybe suggest another way to enforce a sequence of records? It should be a sequence that is sustained over multiple runs, so a simple counter that resets after each server action run isn’t enough as I understand it.

Have you considered setting timestamps at database level as a default, i…e set to timestamp on creation and reset it on update

My server action is basically a GET from an API and then a POST to an API, so I don’t use databases at all. But maybe it’s a good idea to use a intermediary database, thanks for the suggestion.

So as far as you know timestamp in milliseconds is not natively supported from Wappler?

I’ve did some Googling and found that I could use the following:

image

This produces the time in milliseconds, so that’s good to know. Only it produces this timestamp once it seems, at the beginning of the server action. That’s why there is still no sequence, since the time is the same in each repeat.

image

I’m wondering if there is any way to request the timestamp each repeat step.

Why not make you own sequence in the repeat, use

{{ ($_SERVER.REQUEST_TIME_FLOAT * 1000) + $index }}
2 Likes