#!/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
from ecflow import Defs, Suite, Task, Edit, Defstatus, Client, Trigger

print("Creating the DQC suite definition")

# ECFLOW home directory
ecflow_home='/data/joan/c3s512-wp1-datachecker/dqc_workflow'

# ECFLOW definitions
defs = Defs(
    Suite('DQC_tasks',
          Defstatus("suspended"),
          Edit(ECF_HOME=ecflow_home, ECF_INCLUDE=ecflow_home, ECF_FILES=ecflow_home+'/tasks'),
          Task("t1"),
          Task("t2").add(Trigger("t1 eq complete")),
          Task("t3").add(Trigger("t2 eq complete")),
          Task("t4").add(Trigger("t3 eq complete")),
          Task("t5").add(Trigger("t4 eq complete"))
    )
)

# ECFLOW create job
print("Checking job creation: .ecf -> .job0")
defs.check_job_creation(verbose=True)

print("Saving definition ...")
defs.save_as_defs("dqc_workflow.def")

# We can assert, so that we only progress once job creation works
# assert len(defs.check_job_creation()) == 0, "Job generation failed"