The ecflow server records all commands sent to it, in a log file (<host>.<port>.ecf.log)

This log file will grow over time to a considerable size.

In this exercise, we will create a task, whose job is to periodically back up and clear this log file.

This will be done with cron attribute introduced in the previous page. A cron will run indefinitely. i.e. once it has completed it will automatically re-queue itself.

For more examples of adding a cron see the user manual and ecFlow Python Api

Ecf Script

We will create a new script, clear_log.ecf

%include <head.h>

# copy the log file to the ECF_HOME/log directory
cp %ECF_LOG% %ECF_HOME%/log/.
 
# clear the log file
ecflow_client  --log=clear

%include <tail.h>

 Text

For brevity, the previous families have been omitted.

# Definition of the suite test.
suite test
 edit ECF_INCLUDE "$HOME/course"    # replace '$HOME' with the path to your home directory
 edit ECF_HOME    "$HOME/course"
 family house_keeping
     task clear_log
       cron -w 0 22:30  # run every Sunday at 10:30pm
 endfamily
endsuite

Python

For brevity, the previous families have been omitted.

import os
from ecflow import Defs,Suite,Family,Task,Edit,Trigger,Complete,Event,Meter,Cron
 
def create_family_house_keeping():
    return Family("house_keeping",
                Task("clear_log", 
                    Cron("22:30",days_of_week=[0])))  
         
print("Creating suite definition")  
home = os.path.join(os.getenv("HOME"), "course")
defs = Defs( 
        Suite("test",
            Edit(ECF_INCLUDE=home,ECF_HOME=home),
            create_family_house_keeping()))
print(defs) 
 
print("Checking job creation: .ecf -> .job0")  
print(defs.check_job_creation())
 
print("Checking trigger expressions")
errors = defs.check()
assert len(errors) == 0,errors

print("Saving definition to file 'test.def'")
defs.save_as_defs("test.def")

What to do

  1. Make the changes to the suite definition file
  2. Create all the necessary ecf script‘s 
  3. Replace the suite
    python:  python3 test.py; python3 client.py
    text:       ecflow_client --suspend=/test  ;  ecflow_client --replace=/test  test.def
  4. ecflow_ui  has a special window to explain why a task is queued. Select a queued task and  click on the 'Why tab'
  5. Manually run the task. Examine the log file on disk.