예제 #1
0
class ToolA(Tool):
    def cmd(self):
        return NOOP


class ToolB(Tool):
    def cmd(self):
        return NOOP


class ToolC(Tool):
    def cmd(self):
        return NOOP


cosmos = Cosmos()
cosmos.initdb()

workflow = cosmos.start("One2One", "/tmp", check_output_dir=False)
stageA_tasks = workflow.add(ToolA(params=dict(i=i)) for i in [1, 2])
stageB_tasks = workflow.add(
    ToolB(params=task.params, parents=[task]) for task in stageA_tasks)
draw_task_graph(workflow.task_graph(), "one2one.png", format="png")

workflow = cosmos.start("One2Many", "/tmp", check_output_dir=False)
stageA_tasks = workflow.add(ToolA(params=dict(i=i)) for i in [1, 2])
stageB_tasks = workflow.add(
    ToolB(params=dict(j=j, **task.params), parents=[task])
    for task in stageA_tasks for j in ["a", "b"])
draw_task_graph(workflow.task_graph(), "one2many.png", format="png")
예제 #2
0
class ToolA(Tool):
    def cmd(self):
        return NOOP


class ToolB(Tool):
    def cmd(self):
        return NOOP


class ToolC(Tool):
    def cmd(self):
        return NOOP


cosmos = Cosmos()
cosmos.initdb()

execution = cosmos.start('One2One', '/tmp', check_output_dir=False)
stageA_tasks = execution.add(ToolA(tags=dict(i=i)) for i in [1, 2])
stageB_tasks = execution.add(
    ToolB(tags=task.tags, parents=[task]) for task in stageA_tasks)
draw_task_graph(execution.task_graph(), 'one2one.png', format='png')

execution = cosmos.start('One2Many', '/tmp', check_output_dir=False)
stageA_tasks = execution.add(ToolA(tags=dict(i=i)) for i in [1, 2])
stageB_tasks = execution.add(
    ToolB(tags=dict(j=j, **task.tags), parents=[task]) for task in stageA_tasks
    for j in [1, 2])
draw_task_graph(execution.task_graph(), 'one2many.png', format='png')
예제 #3
0
from ex1 import run_ex1
import os
from cosmos.util.helpers import mkdir

def run_ex3(execution):
    @signal_execution_status_change.connect
    def sig(ex):
        msg = "%s %s" % (ex, ex.status)
        if ex.status in [ExecutionStatus.successful, ExecutionStatus.failed, ExecutionStatus.killed]:
            text_message(msg)
            ex.log.info('Sent a text message')

    def text_message(message):
        from twilio.rest import TwilioRestClient

        account = "XYZ"
        token = "XYZ"
        client = TwilioRestClient(account, token)

        message = client.messages.create(to="+1231231234", from_="+1231231234", body=message)

    run_ex1(execution)


if __name__ == '__main__':
    cosmos = Cosmos('sqlite:///%s/sqlite.db' % os.path.dirname(os.path.abspath(__file__)))
    cosmos.initdb()
    mkdir('out')

    execution = cosmos.start('Example1', 'out/ex1', max_attempts=2, restart=True, skip_confirm=True)
    run_ex1(execution)
예제 #4
0
class ToolA(Tool):
    def cmd(self):
        return NOOP


class ToolB(Tool):
    def cmd(self):
        return NOOP


class ToolC(Tool):
    def cmd(self):
        return NOOP


cosmos = Cosmos()
cosmos.initdb()

workflow = cosmos.start('One2One', '/tmp', check_output_dir=False)
stageA_tasks = workflow.add(ToolA(params=dict(i=i))
                             for i in [1, 2])
stageB_tasks = workflow.add(ToolB(params=task.params, parents=[task])
                             for task in stageA_tasks)
draw_task_graph(workflow.task_graph(), 'one2one.png', format='png')

workflow = cosmos.start('One2Many', '/tmp', check_output_dir=False)
stageA_tasks = workflow.add(ToolA(params=dict(i=i))
                             for i in [1, 2])
stageB_tasks = workflow.add(ToolB(params=dict(j=j, **task.params), parents=[task])
                             for task in stageA_tasks
                             for j in ['a','b'])
예제 #5
0
from cosmos import Cosmos, Input
import tools
from cosmos.util.helpers import mkdir


def run_ex2(execution):
    # TODO update this
    pass
    # # These tasks have no dependencies
    # inpts = execution.add([Input('/tmp', 'tmp_dir', 'dir', dict(test='tag'))])
    # echos = execution.add([tools.Echo(dict(word='hello')), tools.Echo(tags=dict(word='world'))])
    #
    # # This task always fails
    # fails = execution.add(tools.Fail, inpts)
    #
    # # Not dependent on the task that failed, will be executed
    # sleeps = execution.add(tools.Sleep(dict(time=5), [inp]) for inp in inpts)
    #
    # # This will not run, because it depends on a task that failed
    # cats = execution.add(tools.Cat(parents=[echos[0], fails[0]]))
    #
    # execution.run()


if __name__ == '__main__':
    cosmos = Cosmos('sqlite:///sqlite.db')
    cosmos.initdb()
    mkdir('out_dir')

    ex = cosmos.start('Failed_Task', 'out_dir/failed_task', max_attempts=2, restart=True, skip_confirm=True)
    run_ex2(ex)
예제 #6
0
                ExecutionStatus.killed
        ]:
            text_message(msg)
            ex.log.info('Sent a text message')

    def text_message(message):
        from twilio.rest import TwilioRestClient

        account = "XYZ"
        token = "XYZ"
        client = TwilioRestClient(account, token)

        message = client.messages.create(to="+1231231234",
                                         from_="+1231231234",
                                         body=message)

    main(execution)


if __name__ == '__main__':
    cosmos = Cosmos('sqlite:///%s/sqlite.db' %
                    os.path.dirname(os.path.abspath(__file__)))
    cosmos.initdb()
    mkdir('out')

    execution = cosmos.start('Example1',
                             'out/ex1',
                             max_attempts=2,
                             restart=True,
                             skip_confirm=True)
    main(execution)
예제 #7
0
class ToolA(Tool):
    def cmd(self):
        return NOOP


class ToolB(Tool):
    def cmd(self):
        return NOOP


class ToolC(Tool):
    def cmd(self):
        return NOOP


cosmos = Cosmos()
cosmos.initdb()

execution = cosmos.start('One2One', '/tmp', check_output_dir=False)
stageA_tasks = execution.add(ToolA(tags=dict(i=i))
                             for i in [1, 2])
stageB_tasks = execution.add(ToolB(tags=task.tags, parents=[task])
                             for task in stageA_tasks)
draw_task_graph(execution.task_graph(), 'one2one.png', format='png')

execution = cosmos.start('One2Many', '/tmp', check_output_dir=False)
stageA_tasks = execution.add(ToolA(tags=dict(i=i))
                             for i in [1, 2])
stageB_tasks = execution.add(ToolB(tags=dict(j=j, **task.tags), parents=[task])
                             for task in stageA_tasks
                             for j in ['a','b'])
예제 #8
0
from cosmos import Execution, add_execution_args, Cosmos
from configparser import ConfigParser
from cosmos.util.helpers import mkdir

root_path = os.path.dirname(os.path.realpath(__file__))
config = ConfigParser()
config.read(os.path.join(root_path, "settings.conf"))
settings = config["main"]

if __name__ == "__main__":
    import ex1
    import ex_fail
    import ex_email

    cosmos = Cosmos("sqlite:///%s/sqlite.db" % os.path.dirname(os.path.abspath(__file__)))
    cosmos.initdb()

    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-g", "--growl", action="store_true", help="sends a growl notification on execution status changes"
    )
    parser.add_argument("-d", "--debug", action="store_true", help="launch ipdb on exception")
    sps = parser.add_subparsers(title="Commands", metavar="<command>")

    sp = sps.add_parser("resetdb", help=cosmos.resetdb.__doc__)
    sp.set_defaults(func=cosmos.resetdb)

    sp = sps.add_parser("initdb", help=cosmos.initdb.__doc__)
예제 #9
0
# game = Game(ballpark=ballpark, league=l, home_team=home_team,
#             away_team=random.choice([t for t in l.teams if t is not home_team]),
#             rules=Rules(), radio=False, trace=True); game._transpire()
# # inning = Inning(game=game, number=5); frame = Frame(inning=inning, bottom=True); ab = AtBat(frame=frame); ab._transpire(); print ab.result
# # ab.draw_playing_field()
# # frame = Frame(inning=inning, bottom=True); ab = AtBat(frame=frame);
#
# # for i in xrange(31):
# #     l.conduct_season()
# #     us.year += 1
# #     l.conduct_offseason_activity()
# #     for player in us.players:
# #         player.potentially_retire()

from baseball.league import League
c = Cosmos()
usa = c.countries[0]
# c.progress(until=(1670, 2, 19))
c.progress(until=(1854, 2, 19))
l = League(usa.find('New York'), c.baseball_classifications[0])
c.progress(until=(1901, 1, 1))

# from baseball.league import League
# c.leagues = []
# l = League(country=usa)
# ump = random.choice([q for q in usa.residents if q.male and q.age > 50])
# ump.umpire = Umpire(person=ump)
# l.umpire = ump.umpire
# game = Game(home_team=list(l.teams)[0], away_team=list(l.teams)[1], trace=True)
# print game
# game._transpire()
예제 #10
0
from cosmos import Execution, add_execution_args, Cosmos
from configparser import ConfigParser
from cosmos.util.helpers import mkdir

root_path = os.path.dirname(os.path.realpath(__file__))
config = ConfigParser()
config.read(os.path.join(root_path, 'settings.conf'))
settings = config['main']

if __name__ == '__main__':
    import ex1
    import ex_fail
    import ex_email

    cosmos = Cosmos('sqlite:///%s/sqlite.db' %
                    os.path.dirname(os.path.abspath(__file__)))

    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-g',
        '--growl',
        action='store_true',
        help='sends a growl notification on execution status changes')
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        help='launch ipdb on exception')
    sps = parser.add_subparsers(title="Commands", metavar="<command>")
예제 #11
0
def main(execution):
    # These tasks have no dependencies
    inpts = execution.add([Input('/tmp', 'tmp_dir', 'dir', dict(test='tag'))])
    echos = execution.add(
        [tools.Echo(dict(word='hello')),
         tools.Echo(tags=dict(word='world'))])

    # This task always fails
    fails = execution.add(tools.Fail, inpts)

    # Not dependent on the task that failed, will be executed
    sleeps = execution.add(tools.Sleep(dict(time=5), [inp]) for inp in inpts)

    # This will not run, because it depends on a task that failed
    cats = execution.add(tools.Cat(parents=[echos[0], fails[0]]))

    execution.run()


if __name__ == '__main__':
    cosmos = Cosmos('sqlite:///sqlite.db')
    cosmos.initdb()
    mkdir('out')

    ex = cosmos.start('Failed_Task',
                      'out/failed_task',
                      max_attempts=2,
                      restart=True,
                      skip_confirm=True)
    main(ex)
예제 #12
0
파일: main.py 프로젝트: jakirkham/Cosmos2
from cosmos import Execution, add_execution_args, Cosmos
from configparser import ConfigParser
from cosmos.util.helpers import mkdir

root_path = os.path.dirname(os.path.realpath(__file__))
config = ConfigParser()
config.read(os.path.join(root_path, 'settings.conf'))
settings = config['main']

if __name__ == '__main__':
    import ex1
    import ex_fail
    import ex_email

    cosmos = Cosmos('sqlite:///%s/sqlite.db' % os.path.dirname(os.path.abspath(__file__)))

    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('-g', '--growl', action='store_true',
                        help='sends a growl notification on execution status changes')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='launch ipdb on exception')
    sps = parser.add_subparsers(title="Commands", metavar="<command>")

    sp = sps.add_parser('resetdb', help=cosmos.resetdb.__doc__)
    sp.set_defaults(func=cosmos.resetdb)

    sp = sps.add_parser('initdb', help=cosmos.initdb.__doc__)
    sp.set_defaults(func=cosmos.initdb)