Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irregular timestamp evaluation in templates #311

Open
reubenmiller opened this issue Sep 12, 2023 · 1 comment
Open

irregular timestamp evaluation in templates #311

reubenmiller opened this issue Sep 12, 2023 · 1 comment

Comments

@reubenmiller
Copy link
Owner

There is a strange behaviour where the timestamp is not being evaluated too early for the first 3 elements, then afterwards the timestamp works as expected.

This behaviour is reproducible via the following snippet:

c8y util repeat 5 \
| c8y events create --device 12345 --type "myType" --template "{c8y_Winding:{temperature:{value: 25.0,unit:'°C'}}}" --dry --delay 5s --text testme --dryFormat json \
| c8y util show --select body.time -o csv

The expected outcome is that the time property should be offset by ~5 seconds for each entry, where as the following clearly shows that the time is not uniformly distributed:

2023-09-12T16:42:16.983+10:00
2023-09-12T16:42:17.313+10:00
2023-09-12T16:42:17.814+10:00
2023-09-12T16:42:22.321+10:00
2023-09-12T16:42:27.328+10:00
@reubenmiller
Copy link
Owner Author

reubenmiller commented Sep 12, 2023

Investigating the issue and the root cause is that the body template is evaluated when the job is added to the queue and not when the request is sent. This leads to the timestamps being unpredictable when using with delay and delayBefore flags.

There might be a way to delay the evaluation of the body though this will likely be a more complex change (which will take longer).

Until this is fixed, then c8y util repeat --delay 5s before the c8y events create (or creating any body using a template)

c8y util repeat 5 \
| c8y util repeat --delay 5s \
| c8y events create --device 12345 --type "myType" --template "{c8y_Winding:{temperature:{value: 25.0,unit:'°C'}}}" --dry --text testme --dryFormat json \
| c8y util show --select body.time -o csv
2023-09-12T20:25:25.541+10:00
2023-09-12T20:25:30.397+10:00
2023-09-12T20:25:35.397+10:00
2023-09-12T20:25:40.398+10:00
2023-09-12T20:25:45.400+10:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant