Starter script

You can do it better :)

But here is the simple sample.

cd /srv/dapu
python3 ./scripts/run_all_targets.py . debug

Script above assumes that you have been deployed your "src" folder into /srv/dapu

And your server is Linux-based (so usually python3, not python).

Sample of run_all_targets.py

import os
from sys import argv

from dapu.enabler import DapuEnabler 
from dapu.registrar import DapuRegistrar 
from dapu.manager import DapuManager 
from dapu.worker import DapuWorker


def analyze_commandline() -> tuple[str | None, list]:
    """
    Analyze command line args, take first which looks like directory, return full path. 
    Other args will be stacked to list and returned as second item of tuple
    Meaningful arg is "debug". 
    """
    targets_root_dir: str | None = None
    extras: list[str] = []
    for arg in argv[1:]: # [0] is current file name, so we ignore it
        # first thing what looks like path will be taken as path ("." is ok)
        if os.path.exists(arg) and os.path.isdir(arg) and not targets_root_dir: 
            targets_root_dir = os.path.realpath(arg)
            continue
        extras.append(arg)
    if targets_root_dir is None: # if zero args...
        targets_root_dir = os.path.realpath(".")
        extras.append("debug") # ...turn ON debug
    return (targets_root_dir, extras)


def run_one_target_fully(main_dir: str, extras: list) -> None:
    """
    Execute all processes (versioning, finding new tasks, adding tasks as jobs to agenda, running jobs) for one target
    """
    ve = DapuEnabler([main_dir] + extras) # versioning (core and project custom)
    ve.run()
    vr = DapuRegistrar([main_dir] + extras) # discovery (task finder from files)
    vr.run()
    vm = DapuManager([main_dir] + extras) # scheduling (agenda by tasks)
    vm.run()
    vw = DapuWorker([main_dir] + extras) # execute jobs from agenda (even if last scheduler didn't addany new jobs)
    vw.run()


if __name__ == '__main__':
    (main_dir, extras) = analyze_commandline()
    if main_dir is not None:
        try:
            run_one_target_fully(main_dir, extras)
        except Exception as e1:
            print(f"Target in {main_dir} failed")
            print(e1)

Possible improvements

One can divide one-time preworks (after-deploy jobs) and regular jobs.

  • Deploy assures that dapu package versioning and your general database versioning and tasks discovery are done.
  • Cron repeatedly runs scheduling and actual execution.

Command line can be analyzed better with argparse.

For file operations use pathlib instead of os.path