#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#
#     Authors:
#       Joan Sala Calero (joan.sala@bsc.es)

import os
import ecflow

print("Client -> Server: delete, then load a new definition")

HOST = os.getenv('ECF_HOST', 'localhost')
PORT = os.getenv('ECF_PORT', 2500)
NAME = os.getenv('SUITE', '/DQC_tasks')

try:
    # Connect to server and ping
    ci = ecflow.Client(HOST, PORT)
    ecflow.USE_TRIGGER = True
    ci.ping()

    #  Clear out the server
    ci.delete_all()

    # Load definition & restart
    ci.load("dqc_workflow.def")
    ci.restart_server()

    # start the suite
    ci.begin_suite(NAME)
    print(ci.stats())
    print(ci.get_defs())

except RuntimeError as e:
    print("Failed:", e)