Fix variables, globals
This commit is contained in:
parent
78ba2af316
commit
392a364aa8
1 changed files with 9 additions and 5 deletions
14
worker.py
14
worker.py
|
@ -11,6 +11,7 @@ logger = Logger()
|
||||||
|
|
||||||
|
|
||||||
def trigger_export(courseid, categoryid):
|
def trigger_export(courseid, categoryid):
|
||||||
|
global MOODLE_PATH, OUTPUT_PATH
|
||||||
output_name = f"course_{courseid}_{categoryid}_{datetime.now().timestamp()}"
|
output_name = f"course_{courseid}_{categoryid}_{datetime.now().timestamp()}"
|
||||||
subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup",
|
subprocess.run([MOOSH_PATH, "-p", MOODLE_PATH, "course-backup",
|
||||||
"-p", OUTPUT_PATH, "-f", output_name, "--template", courseid])
|
"-p", OUTPUT_PATH, "-f", output_name, "--template", courseid])
|
||||||
|
@ -18,23 +19,24 @@ def trigger_export(courseid, categoryid):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
global SIGNAL_PATH, OUTPUT_PATH
|
||||||
logger.info("Moodle Export Worker starting")
|
logger.info("Moodle Export Worker starting")
|
||||||
SIGNAL_PATH = Path(SIGNAL_PATH)
|
SIGNAL_PATH = Path(SIGNAL_PATH)
|
||||||
|
|
||||||
if test.exists():
|
if SIGNAL_PATH.exists():
|
||||||
if not test.is_dir():
|
if not SIGNAL_PATH.is_dir():
|
||||||
logger.fatal(
|
logger.fatal(
|
||||||
f"Cannot create signalling directory {SIGNAL_PATH} because a file with that name exists.")
|
f"Cannot create signalling directory {SIGNAL_PATH} because a file with that name exists.")
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
test.mkdir()
|
SIGNAL_PATH.mkdir()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.fatal(
|
logger.fatal(
|
||||||
f"Cannot create signalling directory {SIGNAL_PATH}: {e}")
|
f"Cannot create signalling directory {SIGNAL_PATH}: {e}")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
for f in test.glob("*-*.mew"):
|
for f in SIGNAL_PATH.glob("*-*.mew"):
|
||||||
logger.debug(f"Found file {f.name} - start processing")
|
logger.debug(f"Found file {f.name} - start processing")
|
||||||
try:
|
try:
|
||||||
pre = datetime.now()
|
pre = datetime.now()
|
||||||
|
@ -48,6 +50,8 @@ def main():
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Export of course {f.name.split('.')[0].split('-')[0]} failed: {e}")
|
f"Export of course {f.name.split('.')[0].split('-')[0]} failed: {e}")
|
||||||
|
|
||||||
|
logger.info("Moodle Export Worker done")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in a new issue