Skip to content

Error handling (cookbook)

David Anderson edited this page Jan 15, 2024 · 3 revisions

The validator will make sure that output files are uppercase. We'll use two-fold replication, and will accept results only if the two instances produce the same result.

Validator

Our validator will use two Python scripts. The first one, validate_init.py, checks whether an output file is valid - in this case, whether it's all uppercase - and exits 0 or 1 accordingly.

def is_uc(path):
    with open(path) as f:
        data = f.read()
    return data == data.upper()

exit(0 if is_uc(sys.argv[1]) else 1)

The second one, validate_compare.py, checks whether 2 output files are identical:

def read(path):
    with open(path) as f:
        data = f.read()
    return data

exit(0 if read(sys.argv[1])==read(sys.argv[2]) else 1)

These scripts are in the BOINC source tree, in samples/worker. Copy them to ~/projects/test/bin.

Add the following to ~/projects/test/config.xml, in the <daemons> section:

<daemon>
   <cmd>script_validator --app worker --init_script "validate_init.py" --compare_script "validate_compare.py" </cmd>
   <output>validator_worker.out</output>
   <pid_file>validator_worker.pid</pid_file>
</daemon>
Clone this wiki locally