fix: tolerate API execution polling through edge
This commit is contained in:
parent
94cd91795e
commit
7aeb50cbae
|
|
@ -12,7 +12,7 @@ access_log /var/log/nginx/crowdsec-access.log;
|
||||||
error_log /var/log/nginx/crowdsec-error.log warn;
|
error_log /var/log/nginx/crowdsec-error.log warn;
|
||||||
|
|
||||||
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
|
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
|
||||||
limit_req_zone $binary_remote_addr zone=jeannie_api:10m rate=2r/s;
|
limit_req_zone $binary_remote_addr zone=jeannie_api:10m rate=5r/s;
|
||||||
|
|
||||||
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_assets:10m max_size=100m inactive=24h;
|
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=static_assets:10m max_size=100m inactive=24h;
|
||||||
proxy_cache_path /var/cache/nginx_dynamic levels=1:2 keys_zone=dynamic_content:5m max_size=50m inactive=1h;
|
proxy_cache_path /var/cache/nginx_dynamic levels=1:2 keys_zone=dynamic_content:5m max_size=50m inactive=1h;
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,13 @@ status, result = request("POST", "/v1/execute", {"command": command, "args": arg
|
||||||
if status != 202:
|
if status != 202:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
execution_id = result["id"]
|
execution_id = result["id"]
|
||||||
|
poll_delay = 1.0
|
||||||
while True:
|
while True:
|
||||||
status, result = request("GET", "/v1/executions/" + execution_id)
|
status, result = request("GET", "/v1/executions/" + execution_id)
|
||||||
|
if status in (429, 503):
|
||||||
|
time.sleep(poll_delay)
|
||||||
|
poll_delay = min(poll_delay * 2, 5.0)
|
||||||
|
continue
|
||||||
if status != 200:
|
if status != 200:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if result["status"] in ("succeeded", "failed"):
|
if result["status"] in ("succeeded", "failed"):
|
||||||
|
|
@ -64,5 +69,6 @@ while True:
|
||||||
if output:
|
if output:
|
||||||
print(output, end="" if output.endswith("\n") else "\n")
|
print(output, end="" if output.endswith("\n") else "\n")
|
||||||
sys.exit(int(result.get("exit_code", 0)))
|
sys.exit(int(result.get("exit_code", 0)))
|
||||||
time.sleep(0.5)
|
poll_delay = 1.0
|
||||||
|
time.sleep(poll_delay)
|
||||||
PY
|
PY
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue