Update job initialization in jobs.py to avoid issues with frames

This commit is contained in:
Théophile Diot 2024-03-22 10:50:21 +00:00
parent fbabbbd8d6
commit b1707d5efe
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06

View file

@ -2,14 +2,13 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from inspect import getsourcefile
from io import BytesIO
from logging import Logger
from os import getenv
from os.path import sep
from pathlib import Path
from shutil import rmtree
from sys import _getframe
from sys import argv
from tarfile import open as tar_open
from threading import Lock
from traceback import format_exc
@ -28,11 +27,16 @@ EXPIRE_TIME = {
class Job:
def __init__(self, logger: Optional[Logger] = None, db=None, *, job_name: str = "", deprecated: bool = False):
source_file = getsourcefile(_getframe(1))
if not argv:
raise ValueError("argv could not be determined.")
source_file = argv[0]
if source_file is None:
raise ValueError("source_file could not be determined.")
elif not logger and not db:
raise ValueError("Either logger or db must be provided.")
source_path = Path(source_file)
self.job_path = Path(sep, "var", "cache", "bunkerweb", source_path.parent.parent.name)
self.job_name = job_name or source_path.name.replace(".py", "")