def process():
    """ provide 'daily' example family """
    return (Family("process").add(
        Trigger("process ne aborted"),  # STOP ASAP
        Family("daily").add(
            Task("simple"), Repeat("YMD", 20180101, 20321212, kind="date"),
            Family("decade").add(Task("simple"),
                                 Label("info", "Show-Icons-Complete"),
                                 Complete("../daily:YMD % 10 ne 0"))),
        Family("monthly").add(
            Task("simple"),
            Trigger("monthly:YM lt daily:YMD / 100 or daily eq complete"),
            Repeat(kind="enum",
                   name="YM",
                   start=[
                       "%d" % YM for YM in range(201801, 203212 + 1)
                       if (YM % 100) < 13 and (YM % 100) != 0
                   ]),
            Family("odd").add(Task("simple"),
                              Complete("../monthly:YM % 2 eq 0"))),
        Family("yearly").add(
            Task("simple"), Repeat("Y", 2018, 2032, kind="integer"),
            Trigger("yearly:Y lt daily:YMD / 10000 or daily eq complete"),
            Family("decade").add(Task("simple"),
                                 Complete("(../yearly:Y % 10) ne 0")),
            Family("century").add(Task("simple"),
                                  Complete("(../yearly:Y % 100) ne 0")))))
def create_families():
    """ provider """
    return (Family("f4").add(
        Variables(SLEEP=2),
        Repeat("NAME", ["a", "b", "c", "d", "e", "f"], kind="enumerated"),
        Task("t1")), Family("f5").add(
            Repeat("DATE", 20170101, 20200105, kind="date"),
            Task("t1").add(Repeat("PARAM", 1, 10, kind="integer"),
                           Label("info", ""))))
def consume1(leap=1, leap_nb=3, producer="."):
    return [Family("%d" % loop).add(
        call_task("consume", "%STEP%", "%STEP%", by * leap_nb).add(
            Repeat("STEP", beg+by*(loop-1), fin, by*leap_nb, kind="integer"),
            trigger("consume:STEP lt %s1/produce:STEP" % producer +
                    " or %s1/produce eq complete" % producer)))
            for loop in range(1, leap_nb + 1)]
def family_for():
    """ for family """
    return (
        Family("for").add(
            process(),
            Repeat(kind="integer", name="STEP", start=1, end=240, step=3)),
        Family("loop").add(process(), Repeat("PARAM", PARAMS, kind="string")),
        Family("parallel").add(Limit("lim", 2), Inlimit("lim"), [
            Family(param).add(Edit(PARAM=param),
                              process().add(Label("info", param)))
            for param in PARAMS
        ]),
        Family("explode").add(
            Limit("lim", 2),
            Inlimit("lim"),
            # LIST COMPREHENSION:
            [Task("t%d" % num) for num in range(1, 5 + 1)]))
示例#5
0
#!/usr/bin/env python2.7
""" back archive example """
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Defs, Defstatus, Suite, Family, Task, Variables, Label,
                 Limit, Inlimit, Repeat, Trigger)
HOME = os.getenv("HOME") + "/ecflow_server"
NAME = "back_archiving"; FILES = HOME + "/back"; DEFS = Defs()
DEFS.add(Suite(NAME).add(
    Defstatus("suspended"),  # so that jobs do not start immediately
    Repeat(kind="day", step=1),
    Variables(ECF_HOME=HOME, ECF_INCLUDE=HOME, ECF_FILES=FILES, SLEEP=2),
    Limit("access", 2),
    [Family(kind).add(
        Repeat("DATE", 19900101, 19950712, kind="date"),
        Variables(KIND=kind),
        Task("get_old").add(Inlimit("access"), Label("info", "")),
        Task("convert").add(Trigger("get_old == complete")),
        Task("save_new").add(Trigger("convert eq complete"))
    ) for kind in ("analysis", "forecast", "climatology", "observations", "images")]))
# print(DEFS); DEFS.generate_scripts(); 
RESULT = DEFS.simulate(); print(RESULT)
CLIENT = ecflow.Client(os.getenv("ECF_HOST", "localhost"),
                       os.getenv("ECF_PORT", 2500))
CLIENT.replace("/%s" % NAME, DEFS)
def call_consumer(selection):
    lead = "/%s/consumer/admin/leader:1" % selection
    prod = "/%s/consumer/produce" % selection

    return Family("consumer").add(
        Defstatus("suspended"),

        Edit(SLEEP=10,
             PRODUCE="no",
             CONSUME="no"),

        Family("limit").add(
            Defstatus("complete"),
            Limit("consume", 7),),

        Family("admin").add(
            # set manually with the GUI or alter the event 1 so
            # that producer 1 becomes leader
            # default: producer0 leads
            Task("leader").add(
                Event("1"),  # text this task is dummy task not designed to run
                Defstatus("complete"))),
        
        Edit(PRODUCE="yes",  # default : task does both produce/consume
             CONSUME="yes"),

        call_task("produce", beg, fin, by).add(
            # this task will do both produde/consume serially            
            Label("info", "both produce and consume in one task")),

        Family("produce0").add(
            # loop inside the task, report progress with a Meter
            not_consumer(),
            Label("info", "loop inside the job"),
            call_task("produce", beg, fin, by)),

        Family("produce1").add(
            # choice is to submit a new job for each step, here        
            Label("info", "loop in the suite (repeat), submit one job per step"),
            not_consumer(),
            call_task("produce", '%STEP%', "%STEP%", by).add(
                Repeat("STEP", beg, fin, by, kind="integer"))),

        Family("consume").add(
            Label("info", "use ecflow_client --wait %TRIGGER% in the job"),
            not_producer(),
            Inlimit("limit:consume"),
            Edit(CALL_WAITER=1,
                 # $step will be interpreted in the job!
                 TRIGGER="../produce:step gt consume:$step or " +
                 "../produce eq complete"),
            call_task("consume", beg, fin, by)),

        Family("consume0or1").add(
            Label("info", "an event may indicate the leader to trigger from"),
            not_producer(),
            Inlimit("limit:consume"),
            call_task("consume", "%STEP%", "%STEP%", by),
            Repeat("STEP", beg, fin, by, kind="integer"),
            trigger("(%s and (consume0or1:STEP lt %s1/produce:STEP" % (
                lead, prod) + " or %s==complete)) or " % prod +
                    "(not %s and (consume0or1:STEP lt %s0/produce:step" % (
                        lead, prod) + " or %s0/produce==complete))" % prod)),

        Family("consume1").add(
            Label("info", "spread consumer in multiple families"),
            not_producer(),
            Inlimit("limit:consume"),
            consume1(producer=prod)),

        Family("consume2").add(
            # change manually with the GUI the limit to reduce/increase the load
            Label("info", "one family per step to consume"),
            Inlimit("limit:consume"),
            not_producer(),
            consume2(beg, fin, prod)))
示例#7
0
    if extn in pathname:  # surround .ecf with head, tail:
        script = "%include <head.h>\n" + script + "\n%include <tail.h>"
    with open(pathname, "w") as destination:  # overwrite!
        print(script, file=destination)
        print("#MSG: created", pathname)


#####################################################################
# suite definition
acq = "acquisition"
deploy("echo acq %TASK%", files + acq + extn)  # create wrapper
post = "postproc"
deploy("ecflow_client --label info %TASK%", files + post + extn)
suite = Suite("course").add(
    Defstatus("suspended"),
    Repeat("YMD", 20180101, 20321212, kind="date"),
    Variables(ECF_HOME=home,  # jobs files are created there by ecflow
              ECF_FILES=home + "/files",  # task-wrappers location
              ECF_INCLUDE=home + "/include",  # include files location
              # ECF_OUT=home,  # output files location on remote systems, 
                               # no directory created there by ecflow...
              ECF_EXTN=extn, ),  # task wrapper extension
    Task(acq).add(Event(1)),
    Family("ensemble").add(  # ENS
        Complete(acq + ":1"),
        [Family("%02d" % num).add(
            Variables(ID=num),
            model(360, dependencies="../../" + acq))  # relative path...
         for num in xrange(0, 10)]),
    model(240, dependencies=acq),  # HRES
    Task(post).add(
#!/usr/bin/env python
""" data acquisition suite example """
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Date, Day, Defs, Defstatus, Suite, Family, Task,
                 If,  # If attribute in use example
                 Edit, Label, Repeat, Time, Trigger, Defs, Client)
HOME = os.getenv("HOME") + "/ecflow_course"; NAME = "data_acquisition"; DEFS = Defs()
DEFS.add(Suite(NAME).add(
    Defstatus("suspended"),  # so that jobs do not start immediately
    Repeat(kind="day", step=1),
    Edit(ECF_HOME=HOME, ECF_INCLUDE=HOME, ECF_FILES=HOME + "/acq", SLEEP=2),
    [Family(city).add(
        Family("archive").add(
            [Family(obs_type).add(
                If(test=city in ("Exeter", "Toulouse", "Offenbach"), then=Time("00:00 23:00 01:00")),
                If(city in ("Washington"), Time("00:00 23:00 03:00")),
                If(city in ("Tokyo"), Time("12:00")),
                If(city in ("Melbourne"), Day("monday")),
                If(city in ("Montreal"), Date("1.*.*")),
                Task("get").add(Label("info", "")),
                Task("process").add(Trigger("get eq complete")),
                Task("store").add(Trigger("get eq complete")))
             for obs_type in ("observations", "fields", "images")]))
        for city in ("Exeter", "Toulouse", "Offenbach", "Washington",
                     "Tokyo", "Melbourne", "Montreal")]))
# print(DEFS); DEFS.generate_scripts(); 
RESULT = DEFS.simulate(); # print(RESULT)
CLIENT = Client(os.getenv("ECF_HOST", "localhost"),
                       os.getenv("ECF_PORT", 2500))