-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move config to variable, use gunicorn
- Loading branch information
Showing
13 changed files
with
148 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,112 @@ | ||
import subprocess | ||
import multiprocessing as mp | ||
import os | ||
import time | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
import click | ||
from prefect import serve, flow, deploy | ||
from prefect.variables import Variable | ||
|
||
from .monitor.app import create_app | ||
from punchpipe.controlsegment.launcher import launcher_flow | ||
from punchpipe.flows.level1 import level1_process_flow, level1_scheduler_flow | ||
from punchpipe.flows.level2 import level2_process_flow, level2_scheduler_flow | ||
from punchpipe.flows.level3 import level3_PTM_process_flow, level3_PTM_scheduler_flow | ||
from punchpipe.flows.levelq import levelq_process_flow, levelq_scheduler_flow | ||
from punchpipe.monitor.app import create_app | ||
|
||
THIS_DIR = os.path.dirname(__file__) | ||
app = create_app() | ||
server = app.server | ||
|
||
@click.group | ||
def main(): | ||
"""Run the PUNCH automated pipeline""" | ||
|
||
def launch_monitor(): | ||
app = create_app() | ||
app.run_server(debug=False, port=8051) | ||
|
||
@flow | ||
def my_flow(): | ||
print("Hello, Prefect!") | ||
|
||
|
||
def serve_flows(): | ||
launcher_deployment = launcher_flow.to_deployment(name="launcher-deployment", | ||
description="Launch a pipeline segment.", | ||
cron="* * * * *", | ||
|
||
) | ||
|
||
level1_scheduler_deployment = level1_scheduler_flow.to_deployment(name="level1-scheduler-deployment", | ||
description="Schedule a Level 1 flow.", | ||
cron="* * * * *", | ||
) | ||
level1_process_deployment = level1_process_flow.to_deployment(name="level1_process_flow", | ||
description="Process a file from Level 0 to Level 1.") | ||
|
||
level2_scheduler_deployment = level2_scheduler_flow.to_deployment(name="level2-scheduler-deployment", | ||
description="Schedule a Level 2 flow.", | ||
cron="* * * * *", | ||
) | ||
level2_process_deployment = level2_process_flow.to_deployment(name="level2_process_flow", | ||
description="Process files from Level 1 to Level 2.") | ||
|
||
levelq_scheduler_deployment = levelq_scheduler_flow.to_deployment(name="levelq-scheduler-deployment", | ||
description="Schedule a Level Q flow.", | ||
cron="* * * * *", | ||
) | ||
levelq_process_deployment = levelq_process_flow.to_deployment(name="levelq_process_flow", | ||
description="Process files from Level 1 to Level Q.") | ||
|
||
level3_PTM_scheduler_deployment = level3_PTM_scheduler_flow.to_deployment(name="level3-PTM-scheduler-deployment", | ||
description="Schedule a Level 3 flow to make PTM.", | ||
cron="* * * * *", | ||
) | ||
level3_PTM_process_deployment = level3_PTM_process_flow.to_deployment(name="level3_PTM_process_flow", | ||
description="Process PTM files from Level 2 to Level 3.") | ||
|
||
serve(launcher_deployment, | ||
level1_scheduler_deployment, level1_process_deployment, | ||
level2_scheduler_deployment, level2_process_deployment, | ||
levelq_scheduler_deployment, levelq_process_deployment, | ||
level3_PTM_scheduler_deployment, level3_PTM_process_deployment, | ||
limit=1000 | ||
) | ||
|
||
|
||
@main.command | ||
def run(): | ||
@click.argument("configuration_path", type=click.Path(exists=True)) | ||
def run(configuration_path): | ||
now = datetime.now() | ||
|
||
configuration_path = str(Path(configuration_path).resolve()) | ||
output_path = f"punchpipe_{now.strftime("%Y%m%d_%H%M%S")}.txt" | ||
|
||
print() | ||
print(f"Launching punchpipe at {now} with configuration: {configuration_path}") | ||
print(f"Terminal logs from punchpipe are in {output_path}.") | ||
print("punchpipe Prefect flows must be stopped manually in Prefect.") | ||
print("Launching Prefect dashboard on http://localhost:4200/.") | ||
print("Launching punchpipe monitor on http://localhost:8051/.") | ||
subprocess.Popen(["prefect", "server", "start"]) | ||
print("\npunchpipe Prefect flows must be stopped manually in Prefect.") | ||
mp.Process(target=launch_monitor, args=()).start() | ||
print("Use ctrl-c to exit.") | ||
|
||
with open(output_path, "w") as f: | ||
prefect_process = subprocess.Popen(["prefect", "server", "start"], | ||
stdout=f, stderr=subprocess.STDOUT) | ||
monitor_process = subprocess.Popen(["gunicorn", | ||
"-b", "0.0.0.0:8051", | ||
"--chdir", THIS_DIR, | ||
"cli:server"], | ||
stdout=f, stderr=subprocess.STDOUT) | ||
time.sleep(3) | ||
Variable.set("punchpipe_config", configuration_path, overwrite=True) | ||
serve_flows() | ||
|
||
try: | ||
prefect_process.wait() | ||
monitor_process.wait() | ||
except Exception: | ||
prefect_process.terminate() | ||
monitor_process.terminate() | ||
|
||
print() | ||
print("punchpipe shut down.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters