Skip to content

Commit d79c134

Browse files
committed
tech: better test_cmd
1 parent 67fd4ea commit d79c134

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

core/management/commands/test_cmd.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import json
2+
from time import sleep
13
from django.core.management.base import BaseCommand
24

35
from core.utils.logs_helpers import log_command_event
46

7+
from django.db import connection
8+
59

610
def log_event(info: str):
711
log_command_event(command_name="test_cmd", info=info)
@@ -32,6 +36,22 @@ def handle(self, *args, **options):
3236
test_int_not_required = options["test_int_not_required"]
3337
test_array = options["test_array"]
3438

39+
log_event("writing args in temp schema")
40+
41+
with connection.cursor() as cursor:
42+
test_table = "test_cmd"
43+
cursor.execute(
44+
f"CREATE TABLE IF NOT EXISTS public.{test_table} (id SERIAL PRIMARY KEY, created_at TIMESTAMP DEFAULT NOW(), args JSONB);"
45+
)
46+
cursor.execute(
47+
f"INSERT INTO public.{test_table} (data) VALUES ('{json.dumps(options)}');"
48+
)
49+
50+
waiting_sec = 120
51+
log_event(f"waiting for {waiting_sec} seconds")
52+
sleep(waiting_sec)
53+
log_event(f"waited for {waiting_sec} seconds")
54+
3555
log_event("args retrieved")
3656

3757
with open("test_cmd.txt", "w") as f:

0 commit comments

Comments
 (0)