Skip to content

Commit 35cbfd3

Browse files
committed
Clear output when re-enqueuing a scheduled script
1 parent fe7002d commit 35cbfd3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

netbox_script_manager/scripts.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _run_script():
251251
script.log_info("Database changes have been reverted automatically.")
252252
clear_webhooks.send(request)
253253

254-
script_execution.data["output"] = output
254+
script_execution.data["output"] = str(output)
255255
script_execution.terminate()
256256
except Exception as e:
257257
if type(e) is AbortScript:
@@ -263,7 +263,7 @@ def _run_script():
263263
logger.error(f"Exception raised during script execution: {e}")
264264
script.log_info("Database changes have been reverted due to error.")
265265

266-
script_execution.data["output"] = output
266+
script_execution.data["output"] = str(output)
267267

268268
script_execution.terminate(status=ScriptExecutionStatusChoices.STATUS_ERRORED)
269269
clear_webhooks.send(request)
@@ -287,6 +287,12 @@ def _run_script():
287287
new_request_id = uuid.uuid4()
288288
request.id = new_request_id
289289

290+
# Maintain the input but clear the output
291+
new_data = {
292+
"input": script_execution.data.get("input"),
293+
"output": None,
294+
}
295+
290296
next_execution = ScriptExecution(
291297
script_instance=script_execution.script_instance,
292298
task_id=uuid.uuid4(),
@@ -296,6 +302,7 @@ def _run_script():
296302
scheduled=new_scheduled_time,
297303
interval=script_execution.interval,
298304
task_queue=script_execution.task_queue,
305+
data=new_data,
299306
)
300307
next_execution.full_clean()
301308
next_execution.save()

0 commit comments

Comments
 (0)