[ZBXNEXT-7101] Implement "sleep" function into zabbix JS engine Created: 2021 Dec 07  Updated: 2024 Apr 10  Resolved: 2022 Feb 14

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Proxy (P), Server (S)
Affects Version/s: None
Fix Version/s: 5.0.20rc1, 5.4.10rc1, 6.0.0beta3, 6.0 (plan)

Type: Change Request Priority: Medium
Reporter: Andrew Biba Assignee: Aleksejs Sestakovs (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Causes
causes ZBX-20530 Compiling error: "ld: error: undefine... Closed
Team: Team B
Sprint: Sprint 83 (Dec 2021), Sprint 84 (Jan 2022), Sprint 85 (Feb 2022)
Story Points: 1

 Description   

It would be nice to have "sleep" function in Zabbix JS engine.

 

Use case:

It would be useful in web-hooks in the case when working with 2 separate services, but services have a delay between data flow.

For example, client have 2 service desk systems, and task creates in fist one, but register in second one in 5-10 seconds, so making 5 second pause between creating task and getting it ID is necessary.



 Comments   
Comment by Yurii Polenok [ 2021 Dec 08 ]

We use the following construction:

function sleep(sleepDuration) {
    var now = new Date().getTime();
    while (new Date().getTime() < now + sleepDuration) { /* do nothing */ }         
}
sleep(5000) 

5000 = 5 sec

Comment by Vjaceslavs Bogdanovs [ 2021 Dec 10 ]

yuriip, we don't recommend doing so as it creates unnecessary load on a CPU. While waiting for 5000, JS would execute millions of loop iterations.

Comment by Aleksejs Sestakovs (Inactive) [ 2022 Jan 13 ]

Available in versions:

Updated documentation:

Generated at Tue Jun 10 07:27:34 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.