Skip to content

Commit 5bfbc72

Browse files
committed
export: added "sleep" producer
see #77765
1 parent bd91127 commit 5bfbc72

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

manifest.master.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@ callbacks:
307307
value: "%_exec.pluginDir%/server/export/error.js"
308308
- type: "value"
309309
value: "%info.json%"
310+
sleep:
311+
exec:
312+
timeoutSec: 120
313+
service: "python3"
314+
commands:
315+
- prog: "python3"
316+
stdout:
317+
type: body
318+
args:
319+
- type: "value"
320+
value: "%_exec.pluginDir%/server/export/sleep.py"
321+
- type: "value"
322+
value: "%info.json%"
310323

311324
transition_db_pre_save:
312325
set_comment:

server/export/sleep.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
import json
3+
import time
4+
5+
def main():
6+
# Check if enough arguments are provided
7+
if len(sys.argv) < 2:
8+
print(f'Wrong number of parameters. Usage: "python3 export_demo.py <info>"', file=sys.stderr)
9+
sys.exit(1)
10+
11+
# Parse the JSON string passed as the second argument (sys.argv[1])
12+
info_json_str = sys.argv[1]
13+
14+
try:
15+
info = json.loads(info_json_str)
16+
except json.JSONDecodeError as e:
17+
print(f"Unable to parse argument <info>: {e}", file=sys.stderr)
18+
sys.exit(1)
19+
20+
sec = float(info["export"]["export"]["produce_options"].get("seconds", 1))
21+
# print(f"Sleeping {sec} seconds")
22+
time.sleep(sec)
23+
24+
info["export"]["_plugin_log"] = [
25+
f"sleeping for {sec}...",
26+
f"slept for {sec}."
27+
]
28+
29+
# Mark export as done and clean up log
30+
info["export"]["_state"] = "done"
31+
info["export"].pop("_log", None) # Remove _log if it exists
32+
33+
# Output the modified export object as pretty-printed JSON
34+
print(json.dumps(info["export"], indent=2))
35+
36+
if __name__ == "__main__":
37+
main()

0 commit comments

Comments
 (0)