Skip to content
Snippets Groups Projects
Commit 3b213898 authored by kaiyou's avatar kaiyou
Browse files

Simplify the tasks cli

parent 98aaaf58
No related branches found
No related tags found
No related merge requests found
import click
import flask
import time
import datetime
from flask import cli from flask import cli
from hiboo import models
from hiboo.profile import common from hiboo.profile import common
tasks = cli.AppGroup("tasks") tasks = cli.AppGroup("tasks")
def run_transitions():
for profile in models.Profile.transition_ready().all():
print("Applying {}/{} to profile {}@{}".format(
profile.transition, profile.transition_step, profile.username, profile.service.name))
common.apply_transition(profile)
models.db.session.commit()
@tasks.command("once") @tasks.command("once")
def tasks_once(): def tasks_once():
""" Run regular tasks """ Run regular tasks
""" """
run_transitions() common.apply_all_transitions()
@tasks.command("loop") @tasks.command("loop")
...@@ -31,6 +17,5 @@ def tasks_loop(): ...@@ -31,6 +17,5 @@ def tasks_loop():
""" Run regular tasks at interval """ Run regular tasks at interval
""" """
while True: while True:
run_transitions() common.apply_all_transitions()
time.sleep(30) time.sleep(30)
from hiboo import models from hiboo import models
def apply_all_transitions():
""" Handle profile transitions for all profiles
"""
for profile in models.Profile.transition_ready().all():
apply_transition(profile)
models.db.session.commit()
def apply_transition(profile): def apply_transition(profile):
""" Handle profile transitions as a three step workflow """ Handle profile transitions as a three step workflow
...@@ -13,6 +21,8 @@ def apply_transition(profile): ...@@ -13,6 +21,8 @@ def apply_transition(profile):
Applying manual action sets the transition as DONE (it never reaches Applying manual action sets the transition as DONE (it never reaches
the step START) the step START)
""" """
print("Applying {}/{} to profile {}@{}".format(
profile.transition, profile.transition_step, profile.username, profile.service.name))
app = profile.service.application app = profile.service.application
transition = profile.transition transition = profile.transition
_, target, _, _, _ = models.Profile.TRANSITIONS[transition] _, target, _, _, _ = models.Profile.TRANSITIONS[transition]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment