Each scheduled task will save their logs into one report independently
from cron time

Next triggered task with the same parameters will append logs into existing file

Related-Prod: PRODX-39606
Change-Id: If2e09b3da77a34a2ef433d067b147ad1f46e60cc
diff --git a/testrail_bot/control/celery_tasks/schedules_pipeline.py b/testrail_bot/control/celery_tasks/schedules_pipeline.py
index ef35323..b121a14 100644
--- a/testrail_bot/control/celery_tasks/schedules_pipeline.py
+++ b/testrail_bot/control/celery_tasks/schedules_pipeline.py
@@ -24,19 +24,22 @@
         return
 
     testrun_obj, _ = models.TestRailTestRun.objects.get_or_create(
-        run_name=f"[by scheduler] {plan_name}",
         run_id=plan_id,
-        caching_tests_enabled=True
     )
-    date = datetime.isoformat(datetime.now())
-    report_name = f"{testrun_obj.run_name}-{date}"
+    testrun_obj.run_name = f"[by scheduler] {plan_name}"
+    testrun_obj.caching_tests_enabled = True
+    testrun_obj.save()
+
+    report_name = f"{testrun_obj.run_name}"
     path = os.path.join(models.fs.location, report_name)
-    with open(path, "w"):
+    with open(path, "a"):
         pass
 
-    report_obj = models.TestRailReport.objects.create(
+    report_obj, _ = models.TestRailReport.objects.get_or_create(
         report_name=report_name,
         path=path)
+    report_obj.finished = False
+    report_obj.save()
 
     return tasks.process_run(bot_run_id=testrun_obj.id,
                              report_id=report_obj.id,
@@ -53,22 +56,24 @@
     """
 
     testrun_obj, _ = models.TestRailTestRun.objects.get_or_create(
-        run_name=f"[by scheduler] plan {testplan_id}",
         run_id=testplan_id,
-        caching_tests_enabled=True
     )
-    date = datetime.isoformat(datetime.now())
-    report_name = f"{testrun_obj.run_name}-{date}"
+    testrun_obj.run_name = f"[by scheduler] plan {testplan_id}"
+    testrun_obj.caching_tests_enabled = True
+    testrun_obj.save()
+
+    report_name = f"{testrun_obj.run_name}"
     path = os.path.join(models.fs.location, report_name)
-    with open(path, "w"):
+    with open(path, "a"):
         pass
 
-    report_obj = models.TestRailReport.objects.create(
+    report_obj, _ = models.TestRailReport.objects.get_or_create(
         report_name=report_name,
         path=path)
+    report_obj.finished = False
+    report_obj.save()
 
     return tasks.process_run(bot_run_id=testrun_obj.id,
                              report_id=report_obj.id,
                              path=path,
                              is_testplan=True)
-
diff --git a/testrail_bot/control/celery_tasks/tasks.py b/testrail_bot/control/celery_tasks/tasks.py
index 38bf022..dcc9cc1 100644
--- a/testrail_bot/control/celery_tasks/tasks.py
+++ b/testrail_bot/control/celery_tasks/tasks.py
@@ -61,3 +61,4 @@
     :return:
     """
     schedules_pipeline.task_to_check_testplan(testplan_id)
+
diff --git a/testrail_bot/control/celery_tasks/testrail_pipeline.py b/testrail_bot/control/celery_tasks/testrail_pipeline.py
index 67d5e18..d0eae11 100644
--- a/testrail_bot/control/celery_tasks/testrail_pipeline.py
+++ b/testrail_bot/control/celery_tasks/testrail_pipeline.py
@@ -347,7 +347,7 @@
     """
     report = models.TestRailReport.objects.get(pk=report_id)
     bot_test_run = models.TestRailTestRun.objects.get(pk=bot_run_id)
-    with open(path, "w") as f:
+    with open(path, "a") as f:
         if is_testplan:
             test_run = test_rail_api.get_plan_by_id(bot_test_run.run_id)
             run_type = "plan"