@@ -13,6 +13,7 @@ from .config import settings
|
||||
from .cleanup import cleanup
|
||||
from .db import Job, claim, initialize, sessions
|
||||
from .storage import storage
|
||||
from .job_types import job_kind, comparison_sources
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
stopping = False
|
||||
@@ -23,19 +24,24 @@ def process(job):
|
||||
try:
|
||||
with tempfile.TemporaryDirectory(prefix='schdoc-') as directory:
|
||||
root = Path(directory)
|
||||
source = root / 'input.SchDoc'
|
||||
comparison = job['input_key'].endswith('/comparison.json')
|
||||
kind = job_kind(job['input_key'])
|
||||
if kind is None: raise ValueError('Unknown job input kind')
|
||||
pcb = kind.startswith('pcb_')
|
||||
source = root / ('input.PcbDoc' if pcb else 'input.SchDoc')
|
||||
comparison = kind.endswith('_comparison')
|
||||
if comparison:
|
||||
manifest = json.loads(storage().get(job['input_key']))
|
||||
source = root / 'comparison.json'
|
||||
source.write_text(json.dumps(manifest), encoding='utf-8')
|
||||
for side in ('old','new'):
|
||||
(root / f'{side}.SchDoc').write_bytes(storage().get(f"{job['id']}/{side}.SchDoc"))
|
||||
for key in comparison_sources(job['input_key']):
|
||||
(root / key.rsplit('/', 1)[-1]).write_bytes(storage().get(key))
|
||||
else:
|
||||
source.write_bytes(storage().get(job['input_key']))
|
||||
env = {k: v for k, v in os.environ.items() if k in ('PATH', 'LANG', 'LC_ALL', 'PYTHONPATH')}
|
||||
# Drain no untrusted output into logs. Kill/wait is handled by subprocess.run.
|
||||
subprocess.run([sys.executable, '-m', 'app.compare_task' if comparison else 'app.parse_task', str(source), str(root), job['filename'], job['id']],
|
||||
task = 'app.pcb_task' if pcb else 'app.compare_task' if comparison else 'app.parse_task'
|
||||
args = [kind] if pcb else []
|
||||
subprocess.run([sys.executable, '-m', task, str(source), str(root), job['filename'], job['id'], *args],
|
||||
timeout=config.parse_timeout, check=True, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
result = json.loads((root / 'result.json').read_text())
|
||||
if result['ok']:
|
||||
|
||||
مرجع در شماره جدید
مسدود کردن کاربر