diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 14e838d..4760f95 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,3 +1,7 @@ import os -os.rename("env", ".env") \ No newline at end of file +os.rename("env", ".env") +os.makedirs( + os.path.join("{{ cookiecutter.bot_id.replace(' ', '_') }}", "framework", "resources"), + exist_ok=True, +) \ No newline at end of file diff --git a/{{ cookiecutter.bot_id.replace(' ', '_') }}/framework/finalize.py b/{{ cookiecutter.bot_id.replace(' ', '_') }}/framework/finalize.py index 5c25988..9b1dbd5 100644 --- a/{{ cookiecutter.bot_id.replace(' ', '_') }}/framework/finalize.py +++ b/{{ cookiecutter.bot_id.replace(' ', '_') }}/framework/finalize.py @@ -72,20 +72,27 @@ def upload_output_orchestrator(): """ Uploads the whole output folder to the BotCity Orchestrator. """ - try: - logger.info( - f"Uploading output to BotCity Orchestrator as Result Files...") - for f in glob.iglob("./output/*"): + logger.info( + f"Uploading output to BotCity Orchestrator as Result Files...") + for f in glob.iglob("./output/*"): + try: fp = Path(f) + # todo add error handling for individual files (e.g. if file is + # locked, too large, etc.) - currently it will just skip and log + # the error STATE.maestro.post_artifact( task_id=STATE.task_id, artifact_name=fp.name, filepath=fp ) - - except Exception as ex: - print(f"Error uploading output to BotCity Orchestrator: {ex}") - raise ex + except Exception as ex: + print(f"Error uploading file {f} to BotCity Orchestrator: {ex}") + STATE.maestro.alert( + task_id=STATE.task_id, + title="Error uploading output to BotCity Orchestrator", + message=f"Error uploading file {f} to BotCity Orchestrator: {ex}. Check the Runner Logs for more details.", + alert_type=AlertType.ERROR) + STATE.maestro.error(task_id=STATE.task_id, exception=ex) def finish_task_orchestrator(): @@ -118,7 +125,36 @@ def finish_status_message() -> str: In our run for task {STATE.task_id} we processed {STATE.total_items} items, from which {STATE.success_count} were with success. Check the Result Files for more details. ''' + # Append optional extra message from STATE.finish_message_extra if + # present + extra = getattr(STATE, "finish_message_extra", None) + if extra: + msg = msg + str(extra) return msg except Exception as ex: logger.error(f"Error generating finish status message: {ex}") return "Task completed. Check the Result Files for more details." + +def append_finish_status_message(extra: str) -> None: + """ + Append extra text to be included into finish_status_message. + Stores a single string at STATE.finish_message_extra (concatenates with newlines). + Will not add the text if an existing line is exactly the same (after trimming). + """ + try: + new = str(extra).strip() + if not new: + return + current = getattr(STATE, "finish_message_extra", "") + # check for exact duplicate among existing lines (trimmed) + existing_lines = [line.strip() + for line in current.splitlines() if line.strip()] + if new in existing_lines: + logger.debug("Duplicate finish status message skipped.") + return + if current: + STATE.finish_message_extra = f"{current} {new}" + else: + STATE.finish_message_extra = new + except Exception as ex: + logger.error(f"Error appending finish status message: {ex}")