zrb 0.0.117__py3-none-any.whl → 0.0.119__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zrb/builtin/__init__.py +2 -2
- zrb/builtin/helper/__init__.py +0 -0
- zrb/builtin/helper/reccuring_action.py +46 -0
- zrb/builtin/schedule.py +12 -22
- zrb/builtin/watch_changes.py +31 -0
- zrb/helper/env_map/fetch.py +6 -6
- zrb/shell-scripts/notify.ps1 +16 -0
- zrb/task/base_remote_cmd_task.py +4 -1
- zrb/task/base_task/__init__.py +0 -0
- zrb/task/{base_task.py → base_task/base_task.py} +62 -201
- zrb/task/base_task/component/__init__.py +0 -0
- zrb/task/base_task/component/base_task_model.py +258 -0
- zrb/task/base_task/component/common_task_model.py +282 -0
- zrb/task/base_task/component/pid_model.py +17 -0
- zrb/task/base_task/component/renderer.py +119 -0
- zrb/task/base_task/component/trackers.py +76 -0
- zrb/task/checker.py +4 -1
- zrb/task/cmd_task.py +56 -36
- zrb/task/docker_compose_task.py +23 -19
- zrb/task/flow_task.py +1 -1
- zrb/task/notifier.py +157 -0
- zrb/task/recurring_task.py +20 -5
- zrb/task/resource_maker.py +1 -1
- zrb/task/task.py +1 -1
- zrb/task/time_watcher.py +2 -2
- zrb/task_env/env.py +26 -14
- zrb/task_env/env_file.py +15 -15
- zrb/task_input/base_input.py +2 -2
- {zrb-0.0.117.dist-info → zrb-0.0.119.dist-info}/METADATA +2 -2
- {zrb-0.0.117.dist-info → zrb-0.0.119.dist-info}/RECORD +33 -23
- zrb/builtin/watch.py +0 -44
- zrb/task/base_task_composite.py +0 -558
- {zrb-0.0.117.dist-info → zrb-0.0.119.dist-info}/LICENSE +0 -0
- {zrb-0.0.117.dist-info → zrb-0.0.119.dist-info}/WHEEL +0 -0
- {zrb-0.0.117.dist-info → zrb-0.0.119.dist-info}/entry_points.txt +0 -0
zrb/builtin/__init__.py
CHANGED
@@ -12,7 +12,7 @@ from zrb.builtin import devtool
|
|
12
12
|
from zrb.builtin import generator
|
13
13
|
from zrb.builtin import process
|
14
14
|
from zrb.builtin import say
|
15
|
-
from zrb.builtin import
|
15
|
+
from zrb.builtin import watch_changes
|
16
16
|
from zrb.builtin import schedule
|
17
17
|
|
18
18
|
assert base64
|
@@ -29,5 +29,5 @@ assert devtool
|
|
29
29
|
assert generator
|
30
30
|
assert process
|
31
31
|
assert say
|
32
|
-
assert
|
32
|
+
assert watch_changes
|
33
33
|
assert schedule
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
from zrb.task.task import Task
|
2
|
+
from zrb.task.cmd_task import CmdTask
|
3
|
+
from zrb.task.notifier import Notifier
|
4
|
+
from zrb.task_input.str_input import StrInput
|
5
|
+
|
6
|
+
|
7
|
+
def create_recurring_action(
|
8
|
+
title: str,
|
9
|
+
default_message: str = '👋'
|
10
|
+
) -> Task:
|
11
|
+
# define inputs
|
12
|
+
message_input = StrInput(
|
13
|
+
name='message',
|
14
|
+
default=default_message,
|
15
|
+
prompt='Message to be shown',
|
16
|
+
)
|
17
|
+
command_input = StrInput(
|
18
|
+
name='command',
|
19
|
+
default='',
|
20
|
+
prompt='Command to be executed',
|
21
|
+
)
|
22
|
+
# define tasks
|
23
|
+
run_command = CmdTask(
|
24
|
+
name='run-command',
|
25
|
+
icon='⚙️',
|
26
|
+
color='blue',
|
27
|
+
inputs=[command_input],
|
28
|
+
should_execute='{{ input.command != "" }}',
|
29
|
+
cmd='{{ input.command }}'
|
30
|
+
)
|
31
|
+
notify = Notifier(
|
32
|
+
name='notify',
|
33
|
+
icon='📢',
|
34
|
+
color='green',
|
35
|
+
inputs=[message_input],
|
36
|
+
title=title,
|
37
|
+
message='{{ input.message }}',
|
38
|
+
should_execute='{{ input.message != "" }}',
|
39
|
+
)
|
40
|
+
# return aggregator task
|
41
|
+
return Task(
|
42
|
+
name='recurring-action',
|
43
|
+
inputs=[message_input, command_input],
|
44
|
+
upstreams=[run_command, notify],
|
45
|
+
retry=0
|
46
|
+
)
|
zrb/builtin/schedule.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
from zrb.task.recurring_task import RecurringTask
|
2
|
-
from zrb.task.cmd_task import CmdTask
|
3
2
|
from zrb.task.time_watcher import TimeWatcher
|
4
3
|
from zrb.task_input.str_input import StrInput
|
5
4
|
from zrb.runner import runner
|
5
|
+
from zrb.builtin.helper.reccuring_action import create_recurring_action
|
6
6
|
|
7
7
|
|
8
8
|
schedule = RecurringTask(
|
9
9
|
name='schedule',
|
10
|
+
icon='📅',
|
11
|
+
color='yellow',
|
10
12
|
description='Show message/run command periodically',
|
11
13
|
inputs=[
|
12
14
|
StrInput(
|
@@ -17,28 +19,16 @@ schedule = RecurringTask(
|
|
17
19
|
),
|
18
20
|
],
|
19
21
|
triggers=[
|
20
|
-
TimeWatcher(
|
22
|
+
TimeWatcher(
|
23
|
+
name='watch-schedule',
|
24
|
+
color='cyan',
|
25
|
+
icon='⏰',
|
26
|
+
schedule='{{input.schedule}}'
|
27
|
+
)
|
21
28
|
],
|
22
|
-
task=
|
23
|
-
|
24
|
-
|
25
|
-
StrInput(
|
26
|
-
name='message',
|
27
|
-
default='👋',
|
28
|
-
prompt='Message to be shown',
|
29
|
-
description='Message to be shown on schedule'
|
30
|
-
),
|
31
|
-
StrInput(
|
32
|
-
name='command',
|
33
|
-
default='',
|
34
|
-
prompt='Command to be executed',
|
35
|
-
description='Command to be executed on schedule'
|
36
|
-
),
|
37
|
-
],
|
38
|
-
cmd=[
|
39
|
-
'{% if input.message != "" %}echo {{ input.message }}{% endif %}',
|
40
|
-
'{% if input.command != "" %}{{ input.command }}{% endif %}',
|
41
|
-
]
|
29
|
+
task=create_recurring_action(
|
30
|
+
title='Schedule',
|
31
|
+
default_message='{{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}}', # noqa
|
42
32
|
)
|
43
33
|
)
|
44
34
|
runner.register(schedule)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from zrb.task.recurring_task import RecurringTask
|
2
|
+
from zrb.task.path_watcher import PathWatcher
|
3
|
+
from zrb.task_input.str_input import StrInput
|
4
|
+
from zrb.runner import runner
|
5
|
+
from zrb.builtin.helper.reccuring_action import create_recurring_action
|
6
|
+
|
7
|
+
|
8
|
+
watch_changes = RecurringTask(
|
9
|
+
name='watch-changes',
|
10
|
+
icon='🕵️',
|
11
|
+
color='yellow',
|
12
|
+
description='Watch changes and show message/run command',
|
13
|
+
inputs=[
|
14
|
+
StrInput(
|
15
|
+
name='pattern',
|
16
|
+
default='*.*',
|
17
|
+
prompt='File pattern',
|
18
|
+
description='File pattern to be watched'
|
19
|
+
),
|
20
|
+
],
|
21
|
+
triggers=[
|
22
|
+
PathWatcher(
|
23
|
+
name='watch-path',
|
24
|
+
color='cyan',
|
25
|
+
icon='👀',
|
26
|
+
path='{{input.pattern}}'
|
27
|
+
)
|
28
|
+
],
|
29
|
+
task=create_recurring_action(title='Watch')
|
30
|
+
)
|
31
|
+
runner.register(watch_changes)
|
zrb/helper/env_map/fetch.py
CHANGED
@@ -42,7 +42,7 @@ def _add_envs_to_env_map(
|
|
42
42
|
env_map: Mapping[str, str], envs: List[Env]
|
43
43
|
) -> Mapping[str, str]:
|
44
44
|
for env in envs:
|
45
|
-
if env.
|
45
|
+
if env.get_os_name() == '':
|
46
46
|
continue
|
47
47
|
env_name = _get_env_name(env)
|
48
48
|
env_default = _get_env_default(env)
|
@@ -64,13 +64,13 @@ def _cascade_env_map(
|
|
64
64
|
|
65
65
|
@typechecked
|
66
66
|
def _get_env_name(env: Env) -> str:
|
67
|
-
if env.
|
68
|
-
return env.
|
69
|
-
return env.
|
67
|
+
if env.get_os_name() is None:
|
68
|
+
return env.get_name()
|
69
|
+
return env.get_os_name()
|
70
70
|
|
71
71
|
|
72
72
|
@typechecked
|
73
73
|
def _get_env_default(env: Env) -> str:
|
74
|
-
if is_probably_jinja(env.
|
74
|
+
if is_probably_jinja(env.get_default()):
|
75
75
|
return ''
|
76
|
-
return env.
|
76
|
+
return env.get_default()
|
@@ -0,0 +1,16 @@
|
|
1
|
+
param (
|
2
|
+
[string]$Title,
|
3
|
+
[string]$Message
|
4
|
+
)
|
5
|
+
|
6
|
+
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
|
7
|
+
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
|
8
|
+
$toastXml = [xml] $template.GetXml()
|
9
|
+
$toastTextElements = $toastXml.GetElementsByTagName("text")
|
10
|
+
$toastTextElements[0].AppendChild($toastXml.CreateTextNode($Title)) # Title
|
11
|
+
$toastTextElements[1].AppendChild($toastXml.CreateTextNode($Message)) # Message
|
12
|
+
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
|
13
|
+
$xml.LoadXml($toastXml.OuterXml)
|
14
|
+
$newToast = [Windows.UI.Notifications.ToastNotification]::new($xml)
|
15
|
+
$toastNotifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Zrb")
|
16
|
+
$toastNotifier.Show($newToast)
|
zrb/task/base_remote_cmd_task.py
CHANGED
@@ -7,7 +7,7 @@ from zrb.task.any_task import AnyTask
|
|
7
7
|
from zrb.task.any_task_event_handler import (
|
8
8
|
OnTriggered, OnWaiting, OnSkipped, OnStarted, OnReady, OnRetry, OnFailed
|
9
9
|
)
|
10
|
-
from zrb.task.base_task import BaseTask
|
10
|
+
from zrb.task.base_task.base_task import BaseTask
|
11
11
|
from zrb.task_env.env import Env
|
12
12
|
from zrb.task_env.env_file import EnvFile
|
13
13
|
from zrb.task_group.group import Group
|
@@ -262,3 +262,6 @@ class BaseRemoteCmdTask(BaseTask):
|
|
262
262
|
retry=0,
|
263
263
|
return_upstream_result=True
|
264
264
|
)
|
265
|
+
|
266
|
+
def __repr__(self) -> str:
|
267
|
+
return f'<BaseRemoteCmdTask name={self._name}>'
|
File without changes
|
@@ -7,34 +7,29 @@ from zrb.task.any_task import AnyTask
|
|
7
7
|
from zrb.task.any_task_event_handler import (
|
8
8
|
OnTriggered, OnWaiting, OnSkipped, OnStarted, OnReady, OnRetry, OnFailed
|
9
9
|
)
|
10
|
-
from zrb.task.
|
11
|
-
AttemptTracker, FinishTracker
|
10
|
+
from zrb.task.base_task.component.trackers import (
|
11
|
+
AttemptTracker, FinishTracker
|
12
12
|
)
|
13
|
+
from zrb.task.base_task.component.renderer import Renderer
|
14
|
+
from zrb.task.base_task.component.base_task_model import BaseTaskModel
|
13
15
|
from zrb.advertisement import advertisements
|
14
16
|
from zrb.task_group.group import Group
|
15
|
-
from zrb.task_env.constant import RESERVED_ENV_NAMES
|
16
17
|
from zrb.task_env.env import Env
|
17
18
|
from zrb.task_env.env_file import EnvFile
|
18
19
|
from zrb.task_input.any_input import AnyInput
|
19
|
-
from zrb.task_input.constant import RESERVED_INPUT_NAMES
|
20
|
-
from zrb.helper.accessories.color import colored
|
21
20
|
from zrb.helper.accessories.name import get_random_name
|
22
21
|
from zrb.helper.advertisement import get_advertisement
|
23
|
-
from zrb.helper.string.modification import double_quote
|
24
22
|
from zrb.helper.string.conversion import to_variable_name
|
25
23
|
from zrb.helper.map.conversion import to_str as map_to_str
|
26
|
-
from zrb.config.config import show_advertisement
|
24
|
+
from zrb.config.config import show_advertisement
|
27
25
|
|
28
26
|
import asyncio
|
29
27
|
import copy
|
30
|
-
import os
|
31
|
-
import sys
|
32
28
|
|
33
29
|
|
34
30
|
@typechecked
|
35
31
|
class BaseTask(
|
36
|
-
FinishTracker, AttemptTracker, Renderer,
|
37
|
-
AnyTask
|
32
|
+
FinishTracker, AttemptTracker, Renderer, BaseTaskModel, AnyTask
|
38
33
|
):
|
39
34
|
'''
|
40
35
|
Base class for all tasks.
|
@@ -74,7 +69,7 @@ class BaseTask(
|
|
74
69
|
FinishTracker.__init__(self)
|
75
70
|
Renderer.__init__(self)
|
76
71
|
AttemptTracker.__init__(self, retry=retry)
|
77
|
-
|
72
|
+
BaseTaskModel.__init__(
|
78
73
|
self,
|
79
74
|
name=name,
|
80
75
|
group=group,
|
@@ -90,66 +85,26 @@ class BaseTask(
|
|
90
85
|
checkers=checkers,
|
91
86
|
checking_interval=checking_interval,
|
92
87
|
run=run,
|
88
|
+
on_triggered=on_triggered,
|
89
|
+
on_waiting=on_waiting,
|
90
|
+
on_skipped=on_skipped,
|
91
|
+
on_started=on_started,
|
92
|
+
on_ready=on_ready,
|
93
|
+
on_retry=on_retry,
|
94
|
+
on_failed=on_failed,
|
93
95
|
should_execute=should_execute,
|
96
|
+
return_upstream_result=return_upstream_result
|
94
97
|
)
|
95
|
-
|
96
|
-
|
97
|
-
self.
|
98
|
-
self.
|
99
|
-
self.
|
100
|
-
self.
|
101
|
-
self._on_ready = on_ready
|
102
|
-
self._on_retry = on_retry
|
103
|
-
self._on_failed = on_failed
|
104
|
-
# init private properties
|
105
|
-
self._is_keyval_set = False # Flag
|
106
|
-
self._all_inputs: Optional[List[AnyInput]] = None
|
107
|
-
self._is_check_triggered: bool = False
|
108
|
-
self._is_ready: bool = False
|
109
|
-
self._is_execution_triggered: bool = False
|
110
|
-
self._is_execution_started: bool = False
|
111
|
-
self._args: List[Any] = []
|
112
|
-
self._kwargs: Mapping[str, Any] = {}
|
98
|
+
# init private flags
|
99
|
+
self.__is_keyval_set = False
|
100
|
+
self.__is_check_triggered: bool = False
|
101
|
+
self.__is_ready: bool = False
|
102
|
+
self.__is_execution_triggered: bool = False
|
103
|
+
self.__is_execution_started: bool = False
|
113
104
|
|
114
105
|
def copy(self) -> AnyTask:
|
115
106
|
return copy.deepcopy(self)
|
116
107
|
|
117
|
-
def _get_combined_inputs(self) -> Iterable[AnyInput]:
|
118
|
-
''''
|
119
|
-
Getting all inputs of this task and all its upstream, non-duplicated.
|
120
|
-
'''
|
121
|
-
if self._all_inputs is not None:
|
122
|
-
return self._all_inputs
|
123
|
-
self._all_inputs: List[AnyInput] = []
|
124
|
-
existing_input_names: Mapping[str, bool] = {}
|
125
|
-
# Add task inputs
|
126
|
-
inputs = self._get_inputs()
|
127
|
-
for input_index, first_occurence_task_input in enumerate(inputs):
|
128
|
-
input_name = first_occurence_task_input.get_name()
|
129
|
-
if input_name in existing_input_names:
|
130
|
-
continue
|
131
|
-
# Look for all input with the same name in the current task
|
132
|
-
task_inputs = [
|
133
|
-
candidate
|
134
|
-
for candidate in inputs[input_index:]
|
135
|
-
if candidate.get_name() == input_name
|
136
|
-
]
|
137
|
-
# Get the last input, and add it to _all_inputs
|
138
|
-
task_input = task_inputs[-1]
|
139
|
-
self._all_inputs.append(task_input)
|
140
|
-
existing_input_names[input_name] = True
|
141
|
-
# Add upstream inputs
|
142
|
-
for upstream in self._get_upstreams():
|
143
|
-
upstream_inputs = upstream._get_combined_inputs()
|
144
|
-
for upstream_input in upstream_inputs:
|
145
|
-
if upstream_input.get_name() in existing_input_names:
|
146
|
-
continue
|
147
|
-
self._all_inputs.append(upstream_input)
|
148
|
-
existing_input_names[upstream_input.get_name()] = True
|
149
|
-
self._allow_add_upstreams = False
|
150
|
-
self._allow_add_inputs = False
|
151
|
-
return self._all_inputs
|
152
|
-
|
153
108
|
def to_function(
|
154
109
|
self,
|
155
110
|
env_prefix: str = '',
|
@@ -229,79 +184,6 @@ class BaseTask(
|
|
229
184
|
'''
|
230
185
|
return await self._is_done()
|
231
186
|
|
232
|
-
def _show_done_info(self):
|
233
|
-
elapsed_time = self._get_elapsed_time()
|
234
|
-
self.print_out_dark(f'Completed in {elapsed_time} seconds')
|
235
|
-
self._play_bell()
|
236
|
-
|
237
|
-
def _get_multiline_repr(self, text: str) -> str:
|
238
|
-
lines_repr: Iterable[str] = []
|
239
|
-
lines = text.split('\n')
|
240
|
-
if len(lines) == 1:
|
241
|
-
return lines[0]
|
242
|
-
for index, line in enumerate(lines):
|
243
|
-
line_number_repr = str(index + 1).rjust(4, '0')
|
244
|
-
lines_repr.append(f' {line_number_repr} | {line}')
|
245
|
-
return '\n' + '\n'.join(lines_repr)
|
246
|
-
|
247
|
-
async def _set_local_keyval(
|
248
|
-
self, kwargs: Mapping[str, Any], env_prefix: str = ''
|
249
|
-
):
|
250
|
-
if self._is_keyval_set:
|
251
|
-
return True
|
252
|
-
self._is_keyval_set = True
|
253
|
-
self.log_info('Set input map')
|
254
|
-
for task_input in self._get_combined_inputs():
|
255
|
-
input_name = self._get_normalized_input_key(task_input.get_name())
|
256
|
-
input_value = kwargs.get(input_name, task_input.get_default())
|
257
|
-
if task_input.should_render():
|
258
|
-
input_value = self.render_any(input_value)
|
259
|
-
self._set_input_map(input_name, input_value)
|
260
|
-
self.log_debug(
|
261
|
-
'Input map:\n' + map_to_str(self.get_input_map(), item_prefix=' ')
|
262
|
-
)
|
263
|
-
self.log_info('Merging task envs, task env files, and native envs')
|
264
|
-
for env_name, env in self._get_combined_env().items():
|
265
|
-
env_value = env.get(env_prefix)
|
266
|
-
if env.should_render:
|
267
|
-
env_value = self.render_any(env_value)
|
268
|
-
self._set_env_map(env_name, env_value)
|
269
|
-
self._set_env_map('_ZRB_EXECUTION_ID', self._execution_id)
|
270
|
-
self.log_debug(
|
271
|
-
'Env map:\n' + map_to_str(self.get_env_map(), item_prefix=' ')
|
272
|
-
)
|
273
|
-
|
274
|
-
def _get_combined_env(self) -> Mapping[str, Env]:
|
275
|
-
all_envs: Mapping[str, Env] = {}
|
276
|
-
for env_name in os.environ:
|
277
|
-
if env_name in RESERVED_ENV_NAMES:
|
278
|
-
continue
|
279
|
-
all_envs[env_name] = Env(
|
280
|
-
name=env_name, os_name=env_name, should_render=False
|
281
|
-
)
|
282
|
-
for env_file in self._get_env_files():
|
283
|
-
for env in env_file.get_envs():
|
284
|
-
all_envs[env.name] = env
|
285
|
-
for env in self._get_envs():
|
286
|
-
all_envs[env.name] = env
|
287
|
-
self._allow_add_envs = False
|
288
|
-
self._allow_add_env_files = False
|
289
|
-
return all_envs
|
290
|
-
|
291
|
-
def _get_normalized_input_key(self, key: str) -> str:
|
292
|
-
if key in RESERVED_INPUT_NAMES:
|
293
|
-
return key
|
294
|
-
return to_variable_name(key)
|
295
|
-
|
296
|
-
def _propagate_execution_id(self):
|
297
|
-
execution_id = self.get_execution_id()
|
298
|
-
for upstream_task in self._get_upstreams():
|
299
|
-
upstream_task._set_execution_id(execution_id)
|
300
|
-
upstream_task._propagate_execution_id()
|
301
|
-
for checker_task in self._get_checkers():
|
302
|
-
checker_task._set_execution_id(execution_id)
|
303
|
-
checker_task._propagate_execution_id()
|
304
|
-
|
305
187
|
async def _run_and_check_all(
|
306
188
|
self,
|
307
189
|
env_prefix: str,
|
@@ -329,8 +211,8 @@ class BaseTask(
|
|
329
211
|
new_kwargs['_args'] = new_args
|
330
212
|
# inject self as input_map['_task']
|
331
213
|
new_kwargs['_task'] = self
|
332
|
-
self.
|
333
|
-
self.
|
214
|
+
self._set_args(new_args)
|
215
|
+
self._set_kwargs(new_kwargs)
|
334
216
|
# run the task
|
335
217
|
coroutines = [
|
336
218
|
asyncio.create_task(
|
@@ -352,28 +234,6 @@ class BaseTask(
|
|
352
234
|
self._show_run_command()
|
353
235
|
self._play_bell()
|
354
236
|
|
355
|
-
def _print_result(self, result: Any):
|
356
|
-
if result is None:
|
357
|
-
return
|
358
|
-
if self._return_upstream_result:
|
359
|
-
# if _return_upstream_result, result is list (see: self._run_all)
|
360
|
-
upstreams = self._get_upstreams()
|
361
|
-
upstream_results = list(result)
|
362
|
-
for upstream_index, upstream_result in enumerate(upstream_results):
|
363
|
-
upstreams[upstream_index]._print_result(upstream_result)
|
364
|
-
return
|
365
|
-
self.print_result(result)
|
366
|
-
|
367
|
-
def print_result(self, result: Any):
|
368
|
-
'''
|
369
|
-
Print result to stdout so that it can be processed further.
|
370
|
-
e.g.: echo $(zrb explain solid) > solid-principle.txt
|
371
|
-
|
372
|
-
You need to override this method
|
373
|
-
if you want to show the result differently.
|
374
|
-
'''
|
375
|
-
print(result)
|
376
|
-
|
377
237
|
async def _loop_check(self, show_done_info: bool = False) -> bool:
|
378
238
|
self.log_info('Start readiness checking')
|
379
239
|
while not await self._cached_check():
|
@@ -385,45 +245,19 @@ class BaseTask(
|
|
385
245
|
selected_advertisement = get_advertisement(advertisements)
|
386
246
|
selected_advertisement.show()
|
387
247
|
self._show_done_info()
|
388
|
-
self._play_bell()
|
389
248
|
await self.on_ready()
|
390
249
|
return True
|
391
250
|
|
392
|
-
def _show_env_prefix(self):
|
393
|
-
if env_prefix == '':
|
394
|
-
return
|
395
|
-
colored_env_prefix = colored(env_prefix, color='yellow')
|
396
|
-
colored_label = colored('Your current environment: ', attrs=['dark'])
|
397
|
-
print(colored(f'{colored_label}{colored_env_prefix}'), file=sys.stderr)
|
398
|
-
|
399
|
-
def _show_run_command(self):
|
400
|
-
params: List[str] = [double_quote(arg) for arg in self._args]
|
401
|
-
for task_input in self._get_combined_inputs():
|
402
|
-
if task_input.is_hidden():
|
403
|
-
continue
|
404
|
-
key = task_input.get_name()
|
405
|
-
kwarg_key = self._get_normalized_input_key(key)
|
406
|
-
quoted_value = double_quote(str(self._kwargs[kwarg_key]))
|
407
|
-
params.append(f'--{key} {quoted_value}')
|
408
|
-
run_cmd = self._get_full_cmd_name()
|
409
|
-
run_cmd_with_param = run_cmd
|
410
|
-
if len(params) > 0:
|
411
|
-
param_str = ' '.join(params)
|
412
|
-
run_cmd_with_param += ' ' + param_str
|
413
|
-
colored_command = colored(run_cmd_with_param, color='yellow')
|
414
|
-
colored_label = colored('To run again: ', attrs=['dark'])
|
415
|
-
print(colored(f'{colored_label}{colored_command}'), file=sys.stderr)
|
416
|
-
|
417
251
|
async def _cached_check(self) -> bool:
|
418
|
-
if self.
|
252
|
+
if self.__is_check_triggered:
|
419
253
|
self.log_debug('Waiting readiness flag to be set')
|
420
|
-
while not self.
|
254
|
+
while not self.__is_ready:
|
421
255
|
await asyncio.sleep(0.1)
|
422
256
|
return True
|
423
|
-
self.
|
257
|
+
self.__is_check_triggered = True
|
424
258
|
check_result = await self._check()
|
425
259
|
if check_result:
|
426
|
-
self.
|
260
|
+
self.__is_ready = True
|
427
261
|
self.log_debug('Set readiness flag to True')
|
428
262
|
return check_result
|
429
263
|
|
@@ -437,7 +271,7 @@ class BaseTask(
|
|
437
271
|
if len(self._checkers) == 0:
|
438
272
|
return await self.check()
|
439
273
|
self.log_debug('Waiting execution to be started')
|
440
|
-
while not self.
|
274
|
+
while not self.__is_execution_started:
|
441
275
|
# Don't start checking before the execution itself has been started
|
442
276
|
await asyncio.sleep(0.1)
|
443
277
|
check_coroutines: Iterable[asyncio.Task] = []
|
@@ -453,7 +287,7 @@ class BaseTask(
|
|
453
287
|
await self._mark_awaited()
|
454
288
|
coroutines: Iterable[asyncio.Task] = []
|
455
289
|
# Add upstream tasks to processes
|
456
|
-
self.
|
290
|
+
self._lock_upstreams()
|
457
291
|
for upstream_task in self._get_upstreams():
|
458
292
|
upstream_task._set_execution_id(self.get_execution_id())
|
459
293
|
coroutines.append(asyncio.create_task(
|
@@ -468,15 +302,15 @@ class BaseTask(
|
|
468
302
|
return results[-1]
|
469
303
|
|
470
304
|
async def _cached_run(self, *args: Any, **kwargs: Any) -> Any:
|
471
|
-
if self.
|
305
|
+
if self.__is_execution_triggered:
|
472
306
|
self.log_debug('Task has been triggered')
|
473
307
|
return
|
474
308
|
await self.on_triggered()
|
475
|
-
self.
|
309
|
+
self.__is_execution_triggered = True
|
476
310
|
await self.on_waiting()
|
477
311
|
# get upstream checker
|
478
312
|
upstream_check_processes: Iterable[asyncio.Task] = []
|
479
|
-
self.
|
313
|
+
self._lock_upstreams()
|
480
314
|
for upstream_task in self._get_upstreams():
|
481
315
|
upstream_check_processes.append(asyncio.create_task(
|
482
316
|
upstream_task._loop_check()
|
@@ -484,7 +318,7 @@ class BaseTask(
|
|
484
318
|
# wait all upstream checkers to complete
|
485
319
|
await asyncio.gather(*upstream_check_processes)
|
486
320
|
# mark execution as started, so that checkers can start checking
|
487
|
-
self.
|
321
|
+
self.__is_execution_started = True
|
488
322
|
local_kwargs = dict(kwargs)
|
489
323
|
local_kwargs['_task'] = self
|
490
324
|
if not await self._check_should_execute(*args, **local_kwargs):
|
@@ -522,7 +356,7 @@ class BaseTask(
|
|
522
356
|
async def _set_keyval(self, kwargs: Mapping[str, Any], env_prefix: str):
|
523
357
|
# if input is not in input_map, add default values
|
524
358
|
for task_input in self._get_combined_inputs():
|
525
|
-
key =
|
359
|
+
key = to_variable_name(task_input.get_name())
|
526
360
|
if key in kwargs:
|
527
361
|
continue
|
528
362
|
kwargs[key] = task_input.get_default()
|
@@ -533,7 +367,7 @@ class BaseTask(
|
|
533
367
|
new_kwargs.update(self.get_input_map())
|
534
368
|
upstream_coroutines = []
|
535
369
|
# set upstreams keyval
|
536
|
-
self.
|
370
|
+
self._lock_upstreams()
|
537
371
|
for upstream_task in self._get_upstreams():
|
538
372
|
upstream_coroutines.append(asyncio.create_task(
|
539
373
|
upstream_task._set_keyval(
|
@@ -555,5 +389,32 @@ class BaseTask(
|
|
555
389
|
coroutines = checker_coroutines + upstream_coroutines
|
556
390
|
await asyncio.gather(*coroutines)
|
557
391
|
|
392
|
+
async def _set_local_keyval(
|
393
|
+
self, kwargs: Mapping[str, Any], env_prefix: str = ''
|
394
|
+
):
|
395
|
+
if self.__is_keyval_set:
|
396
|
+
return True
|
397
|
+
self.__is_keyval_set = True
|
398
|
+
self.log_info('Set input map')
|
399
|
+
for task_input in self._get_combined_inputs():
|
400
|
+
input_name = to_variable_name(task_input.get_name())
|
401
|
+
input_value = kwargs.get(input_name, task_input.get_default())
|
402
|
+
if task_input.should_render():
|
403
|
+
input_value = self.render_any(input_value)
|
404
|
+
self._set_input_map(input_name, input_value)
|
405
|
+
self.log_debug(
|
406
|
+
'Input map:\n' + map_to_str(self.get_input_map(), item_prefix=' ')
|
407
|
+
)
|
408
|
+
self.log_info('Merging task envs, task env files, and native envs')
|
409
|
+
for env_name, env in self._get_combined_env().items():
|
410
|
+
env_value = env.get(env_prefix)
|
411
|
+
if env.should_render():
|
412
|
+
env_value = self.render_any(env_value)
|
413
|
+
self._set_env_map(env_name, env_value)
|
414
|
+
self._set_env_map('_ZRB_EXECUTION_ID', self.get_execution_id())
|
415
|
+
self.log_debug(
|
416
|
+
'Env map:\n' + map_to_str(self.get_env_map(), item_prefix=' ')
|
417
|
+
)
|
418
|
+
|
558
419
|
def __repr__(self) -> str:
|
559
420
|
return f'<BaseTask name={self._name}>'
|
File without changes
|