Skip to content

Commit 1661dc7

Browse files
authored
Feat/issue103 (#107)
* feat(handlers): Swap TK msgbox to console prompts Addresses #103 - Also addressed issue with multiple online Celery worker checks * feat(formatting): improve console output / logging
1 parent 23a4804 commit 1661dc7

File tree

9 files changed

+260
-183
lines changed

9 files changed

+260
-183
lines changed

poetry.lock

+95-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ notify-py = "^0.3.3"
2323
shortuuid = "^1.0.8"
2424
yaspin = "^2.1.0"
2525
ffmpeg-python = "^0.2.0"
26+
asciimatics = "^1.14.0"
2627

2728
[tool.poetry.dev-dependencies]
2829
mkdocs-material = "^7.3.6"

resolve_proxy_encoder/app/checks.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import time
23
from typing import Union
34

45
from rich import print
@@ -17,6 +18,22 @@
1718
logger = logging.getLogger(__name__)
1819

1920

21+
def check_worker_presence():
22+
"""Warn user if no celery workers are available"""
23+
24+
online_workers = celery_app.control.inspect().active_queues()
25+
26+
if not online_workers:
27+
28+
logger.warning(
29+
"[yellow]There are no workers currently online to process jobs!\n"
30+
"Make sure you start at least one."
31+
)
32+
33+
logger.debug(f"[magenta]Online workers:[/]\n{online_workers}")
34+
return online_workers
35+
36+
2037
def check_for_updates(github_url: str, package_name: str) -> Union[dict, None]:
2138

2239
"""Compare git origin to local git or package dist for updates
@@ -88,36 +105,21 @@ def check_for_updates(github_url: str, package_name: str) -> Union[dict, None]:
88105
}
89106

90107

91-
def check_worker_compatability():
108+
def check_worker_compatability(online_workers):
92109

93110
if settings["app"]["disable_version_constrain"]:
94111
logger.warning(
95112
"[yellow]Version constrain is disabled![/] [red][bold]Thar be dragons :dragon_face:\n"
96113
)
97-
# time.sleep(2)
114+
time.sleep(2)
98115
return
99116

100117
spinner = yaspin(
101118
text="Checking worker compatability...",
102119
color="cyan",
103120
)
104121

105-
# Get online workers and package current commit
106-
spinner.start()
107-
online_workers = celery_app.control.inspect().active_queues()
108-
git_full_sha = pkg_info.get_package_current_commit("resolve_proxy_encoder")
109-
110-
if git_full_sha is None:
111-
spinner.fail("❌ ")
112-
logger.warning(
113-
"[yellow]Couldn't get local package git commit SHA\n"
114-
+ "Any incompatible workers will not be reported.\n"
115-
+ "[red]CONTINUE AT OWN RISK![/]"
116-
)
117-
return
118-
119-
git_short_sha = git_full_sha[-4:]
120-
122+
# Get online workers
121123
if online_workers is None:
122124

123125
spinner.fail("❌ ")
@@ -132,9 +134,20 @@ def check_worker_compatability():
132134

133135
return
134136

135-
spinner.stop()
136-
logger.debug(f"Online workers: {online_workers}")
137+
# Get package current commit
137138
spinner.start()
139+
git_full_sha = pkg_info.get_package_current_commit("resolve_proxy_encoder")
140+
141+
if git_full_sha is None:
142+
spinner.fail("❌ ")
143+
logger.warning(
144+
"[yellow]Couldn't get local package git commit SHA\n"
145+
+ "Any incompatible workers will not be reported.\n"
146+
+ "[red]CONTINUE AT OWN RISK![/]"
147+
)
148+
return
149+
150+
git_short_sha = git_full_sha[-4:]
138151

139152
# Get incompatible workers
140153
incompatible_workers = []

resolve_proxy_encoder/app/cli.py

+41-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from .utils.core import setup_rich_logging
2222

2323

24-
def print_routing_key():
24+
def get_colorized_routing_key():
25+
26+
"""Returns a formatted the routing key based on version info"""
2527

2628
ver_colour = "red"
2729
queue = "Unknown"
@@ -35,7 +37,7 @@ def print_routing_key():
3537
ver_colour = "green" if settings["version_info"]["is_latest"] else "yellow"
3638
queue = settings["version_info"]["commit_short_sha"]
3739

38-
print(f"[cyan]Routing to queue:[/] [{ver_colour}]'{queue}'[/]")
40+
return f"[{ver_colour}]'{queue}'[/]"
3941

4042

4143
# Init classes
@@ -55,11 +57,18 @@ def queue():
5557
Queue proxies from the currently open
5658
DaVinci Resolve timeline
5759
"""
58-
checks.check_worker_compatability()
5960

60-
print_routing_key()
61+
checks.check_worker_compatability(settings["online_workers"])
62+
63+
print("\n")
64+
console.rule(
65+
f"[green bold]Queuing proxies from Resolve's active timeline[/] :outbox_tray:",
66+
align="left",
67+
)
68+
print("\n")
69+
70+
logger.info(f"[cyan]Routing to queue: {get_colorized_routing_key()}\n")
6171

62-
print("\n\n[green]Queuing proxies from Resolve's active timeline[/] :outbox_tray:")
6372
from ..queuer import queue
6473

6574
queue.main()
@@ -74,6 +83,10 @@ def link():
7483

7584
from ..queuer import link
7685

86+
print("\n")
87+
console.rule(f"[green bold]Link proxies[/] :link:", align="left")
88+
print("\n")
89+
7790
link.main()
7891

7992

@@ -87,6 +100,8 @@ def work(
87100
):
88101
"""Prompt to start Celery workers on local machine"""
89102

103+
print("\n")
104+
console.rule(f"[green bold]Start workers[/] :construction_worker:", align="left")
90105
print("\n")
91106

92107
# Print worker queue
@@ -124,6 +139,10 @@ def purge():
124139
None
125140
"""
126141

142+
print("\n")
143+
console.rule(f"[red bold]Purge all tasks! :fire:", align="left")
144+
print("\n")
145+
127146
if Confirm.ask(
128147
"[yellow]Are you sure you want to purge all tasks?\n"
129148
"All active tasks and task history will be lost![/]"
@@ -138,7 +157,12 @@ def mon():
138157
Launch Flower Celery monitor in default browser new window
139158
"""
140159

141-
print("[green]Launching Flower celery monitor[/] :sunflower:")
160+
print("\n")
161+
console.rule(
162+
f"[green bold]Start Flower Celery monitor[/] :sunflower:", align="left"
163+
)
164+
print("\n")
165+
142166
webbrowser.open_new(settings["celery"]["flower_url"])
143167

144168

@@ -148,20 +172,30 @@ def mon():
148172
def config():
149173
"""Open user settings configuration file for editing"""
150174

151-
print("[green]Opening user settings file for modification")
175+
print("\n")
176+
console.rule(
177+
f"[green bold]Open 'user_settings.yaml' config[/] :gear:", align="left"
178+
)
179+
print("\n")
180+
152181
webbrowser.open_new(settings.user_file)
153182

154183

155184
def init():
156185
"""Run before CLI App load."""
157186

187+
# Check for any updates and inject version info into user settings.
158188
version_info = checks.check_for_updates(
159189
github_url=settings["app"]["update_check_url"],
160190
package_name="resolve_proxy_encoder",
161191
)
162192

163193
settings.update({"version_info": version_info})
164194

195+
# Check for online workers to pass to other checks
196+
online_workers = checks.check_worker_presence()
197+
settings.update({"online_workers": online_workers})
198+
165199

166200
def main():
167201
init()

resolve_proxy_encoder/app/utils/core.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def app_exit(level: int = 0, timeout: int = -1, cleanup_funcs: list = []):
5454
x()
5555

5656
if timeout < 0:
57+
print()
5758
answer = Prompt.ask("Press [yellow]ENTER[/] to exit")
5859
sys.exit(level)
5960

0 commit comments

Comments
 (0)