-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.py
65 lines (54 loc) · 1.92 KB
/
sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
"""
Define the `plugin:compose` sync method.
"""
import time
import meerschaum as mrsm
from meerschaum.utils.typing import SuccessTuple, Any, List
from meerschaum.utils.warnings import info
def sync(pipe: mrsm.Pipe, **kwargs: Any) -> SuccessTuple:
"""
Sync the pipe's children one-by-one.
"""
from meerschaum.utils.formatting import make_header, UNICODE
child_successes: List[bool] = []
child_messages: List[str] = []
loop_start = time.perf_counter()
arrow = '⮡' if UNICODE else '->'
for child_num, child_pipe in enumerate(pipe.children):
info(f"{pipe}:\n {arrow} {child_num + 1}. Syncing {child_pipe}...")
child_pipe_start = time.perf_counter()
child_success, child_msg = child_pipe.sync(**kwargs)
child_msg = child_msg.lstrip().rstrip()
child_pipe_duration = time.perf_counter() - child_pipe_start
mrsm.pprint((child_success, child_msg))
child_successes.append(child_success)
child_message = (
(
"Successfully synced in "
if child_success
else "Failed to sync after "
) + f"{round(child_pipe_duration, 2)} seconds:\n"
+ child_msg
)
child_messages.append(child_message)
if not child_success:
break
loop_duration = time.perf_counter() - loop_start
num_synced = len(child_messages)
success = all(child_successes)
msg = (
f"Synced {num_synced} pipe"
+ ('s' if num_synced != 1 else '')
+ f" in {round(loop_duration, 2)} seconds."
)
for child_num, (child_pipe, child_message) in enumerate(
zip(pipe.children, child_messages)
):
child_header = make_header(
str(child_num + 1) + '. ' + str(child_pipe)
)
msg += f"\n\n{child_header}\n{child_message}"
return success, msg