Ejemplo n.º 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")
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)