Adding a cron
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. This section will create a task, whose job is to periodically back up and clear this log file.
This can be done with a cron attribute introduced previously. A cron will run indefinitely i.e. once it has completed it will automatically requeue itself.
More examples of how to add a cron, using the Python API, can be found at Adding Time Dependencies.
Task Script
Create a new task script named 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>
Update Suite Definition
Create a new family named house_keeping and add the task clear_log to it, that will run every Sunday at 10:30pm.
suite test
edit ECF_INCLUDE "{{HOME}}/course" # replace '{{HOME}}' appropriately
edit ECF_HOME "$HOME/course"
[... previous families omitted for brevity ..]
family house_keeping
task clear_log
cron -w 0 22:30 # run every Sunday at 10:30pm
endfamily
endsuite
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:
Update the suite definition to include the new family and task.
Create the new task script
clear_log.ecfin the appropriate directory.Replace the suite, using:
ecflow_client --suspend /test ecflow_client --replace /test test.def
python3 test.py python3 client.py
Use ecflow_ui to inspect why a task is queued, by selecting a queued task and clicking on the Why tab.
Manually run the task, and examine the log file on disk.