tabsdata-cli 2.0.0__cp312-abi3-win_amd64.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.
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/__init__.py +5 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/_registry.py +78 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/BANNER +5 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/LICENSE +3 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/README-PyPi.md +8 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/RELEASE-NOTES +1 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/THIRD-PARTY +3 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/assets/manifest/VERSION +1 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/cli_utils.py +993 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/shell.py +390 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/__init__.py +3 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/auth_group.py +197 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/cli.py +508 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/collection_group.py +458 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/config_utils.py +93 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/connection_group.py +159 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/examples_group.py +206 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/execution_utils.py +429 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/fn_group.py +1109 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/fnrun_group.py +285 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/group_group.py +184 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/metrics_group.py +323 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/permission_group.py +259 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/plan_group.py +324 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/project_group.py +170 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/role_group.py +630 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/settings_group.py +344 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/table_group.py +600 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/trigger_group.py +338 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/trx_group.py +329 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/user_group.py +200 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/td/worker_group.py +185 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/cli/template.py +781 -0
- tabsdata_cli-2.0.0.data/purelib/tabsdatak/py.typed +0 -0
- tabsdata_cli-2.0.0.dist-info/METADATA +39 -0
- tabsdata_cli-2.0.0.dist-info/RECORD +39 -0
- tabsdata_cli-2.0.0.dist-info/WHEEL +5 -0
- tabsdata_cli-2.0.0.dist-info/licenses/src/main/python/tabsdatak/cli/assets/manifest/LICENSE +3 -0
- tabsdata_cli-2.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Tabsdata Inc.
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
"""``tdk cron`` and ``tdk stream``: the two kinds of orchestrator-managed
|
|
6
|
+
trigger.
|
|
7
|
+
|
|
8
|
+
A function registered with a ``CronTrigger`` gets a ``CT`` trigger worker and a
|
|
9
|
+
``@stream_publisher`` gets an ``ST`` one, so a group's ``list`` is the worker
|
|
10
|
+
listing narrowed to that worker type, ``plans`` is the execution-plan listing
|
|
11
|
+
narrowed to the trigger type of the same name, and its ``enable`` / ``disable``
|
|
12
|
+
are ``tdk fn enable`` / ``tdk fn disable`` restricted to functions that have such
|
|
13
|
+
a trigger. The trigger worker is what both read: it is created when the function is
|
|
14
|
+
registered and outlives a disable (the function's own ``workers`` map does not --
|
|
15
|
+
it empties out while the function is disabled, so it cannot tell a disabled cron
|
|
16
|
+
function from a plain one).
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from typing import TYPE_CHECKING, NamedTuple
|
|
22
|
+
|
|
23
|
+
import rich_click as click
|
|
24
|
+
from rich.table import Table
|
|
25
|
+
|
|
26
|
+
from tabsdatak.cli._registry import cli_command
|
|
27
|
+
from tabsdatak.cli.cli_utils import (
|
|
28
|
+
all_projects_option,
|
|
29
|
+
beautify_time,
|
|
30
|
+
echo_more_results,
|
|
31
|
+
format_option,
|
|
32
|
+
get_currently_pinned_object,
|
|
33
|
+
hint_common_solutions,
|
|
34
|
+
logical_prompt,
|
|
35
|
+
make_console,
|
|
36
|
+
max_result_option,
|
|
37
|
+
proj_option,
|
|
38
|
+
render,
|
|
39
|
+
resolve_all_projects,
|
|
40
|
+
take,
|
|
41
|
+
verify_login_or_prompt,
|
|
42
|
+
)
|
|
43
|
+
from tabsdatak.cli.td.execution_utils import (
|
|
44
|
+
obtain_execution_list,
|
|
45
|
+
obtain_list_exec_filters,
|
|
46
|
+
obtain_list_worker_filters,
|
|
47
|
+
plans_table,
|
|
48
|
+
)
|
|
49
|
+
from tabsdatak.cli.td.fn_group import set_function_enabled
|
|
50
|
+
|
|
51
|
+
if TYPE_CHECKING:
|
|
52
|
+
from tabsdatak.sdk.tabsdata_server import TabsdataServer
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class _Kind(NamedTuple):
|
|
56
|
+
"""What differs between the two trigger kinds: the code they are listed by,
|
|
57
|
+
and how they are named in output.
|
|
58
|
+
|
|
59
|
+
``WorkerType`` and ``TriggerType`` share the ``CT``/``ST`` codes, so the one
|
|
60
|
+
value selects both the trigger worker and the plans that trigger started.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
code: str
|
|
64
|
+
title: str
|
|
65
|
+
plural: str
|
|
66
|
+
# Fill the "No <trigger> found for function ... use 'tdk fn <action>' to
|
|
67
|
+
# <action> <other>" refusal. Phrased so it also holds when the function does
|
|
68
|
+
# not exist at all.
|
|
69
|
+
trigger: str
|
|
70
|
+
other: str
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
CRON = _Kind(
|
|
74
|
+
code="CT",
|
|
75
|
+
title="Cron triggers",
|
|
76
|
+
plural="cron triggers",
|
|
77
|
+
trigger="cron trigger",
|
|
78
|
+
other="a function that is not cron-triggered",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
STREAM = _Kind(
|
|
82
|
+
code="ST",
|
|
83
|
+
title="Stream publishers",
|
|
84
|
+
plural="stream publishers",
|
|
85
|
+
trigger="stream-publisher trigger",
|
|
86
|
+
other="a function that is not a stream publisher",
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _name_option(help: str):
|
|
91
|
+
return click.option("--name", "-n", help=help)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _coll_option(help: str):
|
|
95
|
+
return click.option("--coll", "-c", help=help)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@cli_command
|
|
99
|
+
@click.group()
|
|
100
|
+
def cron():
|
|
101
|
+
"""Cron-triggered functions"""
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@cli_command
|
|
105
|
+
@click.group()
|
|
106
|
+
def stream():
|
|
107
|
+
"""Stream-publisher functions"""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@cron.command()
|
|
111
|
+
@proj_option
|
|
112
|
+
@_name_option("Name of the cron-triggered function to enable.")
|
|
113
|
+
@_coll_option("Name of the collection to which the function belongs.")
|
|
114
|
+
@click.pass_context
|
|
115
|
+
def enable(ctx: click.Context, name: str, coll: str):
|
|
116
|
+
"""Enable a cron-triggered function
|
|
117
|
+
|
|
118
|
+
'tdk fn enable' restricted to functions that have a cron trigger; enabling
|
|
119
|
+
an already-enabled one does nothing.
|
|
120
|
+
"""
|
|
121
|
+
_enable_function(ctx, CRON, name, coll, True)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@cron.command()
|
|
125
|
+
@proj_option
|
|
126
|
+
@_name_option("Name of the cron-triggered function to disable.")
|
|
127
|
+
@_coll_option("Name of the collection to which the function belongs.")
|
|
128
|
+
@click.pass_context
|
|
129
|
+
def disable(ctx: click.Context, name: str, coll: str):
|
|
130
|
+
"""Disable a cron-triggered function
|
|
131
|
+
|
|
132
|
+
'tdk fn disable' restricted to functions that have a cron trigger; disabling
|
|
133
|
+
an already-disabled one does nothing.
|
|
134
|
+
"""
|
|
135
|
+
_enable_function(ctx, CRON, name, coll, False)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@cron.command("list")
|
|
139
|
+
@proj_option
|
|
140
|
+
@all_projects_option
|
|
141
|
+
@_name_option("Only list the trigger of this function.")
|
|
142
|
+
@_coll_option("Only list triggers of functions in this collection.")
|
|
143
|
+
@format_option
|
|
144
|
+
@max_result_option
|
|
145
|
+
@click.pass_context
|
|
146
|
+
def list_crons(ctx: click.Context, all_projects: bool, name: str, coll: str):
|
|
147
|
+
"""List the cron triggers of the project"""
|
|
148
|
+
_list_triggers(ctx, CRON, all_projects, name, coll)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@cron.command("plans")
|
|
152
|
+
@proj_option
|
|
153
|
+
@all_projects_option
|
|
154
|
+
@_name_option("Only list the plans triggered for this function.")
|
|
155
|
+
@_coll_option("Only list the plans of functions in this collection.")
|
|
156
|
+
@format_option
|
|
157
|
+
@max_result_option
|
|
158
|
+
@click.pass_context
|
|
159
|
+
def list_cron_plans(ctx: click.Context, all_projects: bool, name: str, coll: str):
|
|
160
|
+
"""List the execution plans the cron triggers started, newest first"""
|
|
161
|
+
_list_plans(ctx, CRON, all_projects, name, coll)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@stream.command("enable")
|
|
165
|
+
@proj_option
|
|
166
|
+
@_name_option("Name of the stream-publisher function to enable.")
|
|
167
|
+
@_coll_option("Name of the collection to which the function belongs.")
|
|
168
|
+
@click.pass_context
|
|
169
|
+
def enable_stream(ctx: click.Context, name: str, coll: str):
|
|
170
|
+
"""Enable a stream-publisher function
|
|
171
|
+
|
|
172
|
+
'tdk fn enable' restricted to stream publishers; enabling an already-enabled
|
|
173
|
+
one does nothing.
|
|
174
|
+
"""
|
|
175
|
+
_enable_function(ctx, STREAM, name, coll, True)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@stream.command("disable")
|
|
179
|
+
@proj_option
|
|
180
|
+
@_name_option("Name of the stream-publisher function to disable.")
|
|
181
|
+
@_coll_option("Name of the collection to which the function belongs.")
|
|
182
|
+
@click.pass_context
|
|
183
|
+
def disable_stream(ctx: click.Context, name: str, coll: str):
|
|
184
|
+
"""Disable a stream-publisher function
|
|
185
|
+
|
|
186
|
+
'tdk fn disable' restricted to stream publishers; disabling an
|
|
187
|
+
already-disabled one does nothing.
|
|
188
|
+
"""
|
|
189
|
+
_enable_function(ctx, STREAM, name, coll, False)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@stream.command("list")
|
|
193
|
+
@proj_option
|
|
194
|
+
@all_projects_option
|
|
195
|
+
@_name_option("Only list the publisher of this function.")
|
|
196
|
+
@_coll_option("Only list publishers of functions in this collection.")
|
|
197
|
+
@format_option
|
|
198
|
+
@max_result_option
|
|
199
|
+
@click.pass_context
|
|
200
|
+
def list_streams(ctx: click.Context, all_projects: bool, name: str, coll: str):
|
|
201
|
+
"""List the stream publishers of the project"""
|
|
202
|
+
_list_triggers(ctx, STREAM, all_projects, name, coll)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@stream.command("plans")
|
|
206
|
+
@proj_option
|
|
207
|
+
@all_projects_option
|
|
208
|
+
@_name_option("Only list the plans triggered for this function.")
|
|
209
|
+
@_coll_option("Only list the plans of functions in this collection.")
|
|
210
|
+
@format_option
|
|
211
|
+
@max_result_option
|
|
212
|
+
@click.pass_context
|
|
213
|
+
def list_stream_plans(ctx: click.Context, all_projects: bool, name: str, coll: str):
|
|
214
|
+
"""List the execution plans the stream publishers started, newest first"""
|
|
215
|
+
_list_plans(ctx, STREAM, all_projects, name, coll)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _triggers_of(server: "TabsdataServer", kind: _Kind, coll: str, name: str):
|
|
219
|
+
request_filter = obtain_list_worker_filters(
|
|
220
|
+
fn=name, collection=coll, worker_type=kind.code
|
|
221
|
+
)
|
|
222
|
+
return server.list_workers_generator(filter=request_filter)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _enable_function(
|
|
226
|
+
ctx: click.Context, kind: _Kind, name: str, coll: str, enabled: bool
|
|
227
|
+
):
|
|
228
|
+
verify_login_or_prompt(ctx)
|
|
229
|
+
name = name or logical_prompt(ctx, "Name of the function")
|
|
230
|
+
coll = (
|
|
231
|
+
coll
|
|
232
|
+
or get_currently_pinned_object(ctx, "collection")
|
|
233
|
+
or logical_prompt(ctx, "Name of the collection to which the function belongs")
|
|
234
|
+
)
|
|
235
|
+
action = "enable" if enabled else "disable"
|
|
236
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
237
|
+
try:
|
|
238
|
+
has_trigger = any(True for _ in _triggers_of(server, kind, coll, name))
|
|
239
|
+
except Exception as e:
|
|
240
|
+
hint_common_solutions(ctx, e)
|
|
241
|
+
raise click.ClickException(f"Failed to {action} function: {e}")
|
|
242
|
+
if not has_trigger:
|
|
243
|
+
raise click.ClickException(
|
|
244
|
+
f"No {kind.trigger} found for function '{name}' in collection "
|
|
245
|
+
f"'{coll}'. Use 'tdk fn {action}' to {action} {kind.other}."
|
|
246
|
+
)
|
|
247
|
+
set_function_enabled(ctx, name, coll, enabled)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _list_plans(
|
|
251
|
+
ctx: click.Context,
|
|
252
|
+
kind: _Kind,
|
|
253
|
+
all_projects: bool,
|
|
254
|
+
name: str,
|
|
255
|
+
coll: str,
|
|
256
|
+
):
|
|
257
|
+
verify_login_or_prompt(ctx)
|
|
258
|
+
coll = coll or get_currently_pinned_object(ctx, "collection")
|
|
259
|
+
try:
|
|
260
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
261
|
+
resolve_all_projects(ctx, all_projects)
|
|
262
|
+
request_filter = obtain_list_exec_filters(fn=name, collection=coll)
|
|
263
|
+
request_filter.append(f"trigger_type:eq:{kind.code}")
|
|
264
|
+
# Already newest-first and capped by --max-result.
|
|
265
|
+
plans, truncated = obtain_execution_list(
|
|
266
|
+
ctx, server, request_filter, last=False
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
def _table():
|
|
270
|
+
click.echo()
|
|
271
|
+
title = f"Plans of the {kind.plural}"
|
|
272
|
+
make_console().print(plans_table(plans, title=title))
|
|
273
|
+
click.echo(f"Number of plans: {len(plans)}")
|
|
274
|
+
click.echo()
|
|
275
|
+
|
|
276
|
+
# The listing already returned each row; ``_data`` would re-fetch them
|
|
277
|
+
# one by one, and ``kwargs`` alone drops the id the row was built from.
|
|
278
|
+
render(
|
|
279
|
+
ctx,
|
|
280
|
+
data=lambda: [{"id": plan.id, **plan.kwargs} for plan in plans],
|
|
281
|
+
table=_table,
|
|
282
|
+
)
|
|
283
|
+
echo_more_results(ctx, truncated)
|
|
284
|
+
except Exception as e:
|
|
285
|
+
hint_common_solutions(ctx, e)
|
|
286
|
+
raise click.ClickException(f"Failed to list plans of the {kind.plural}: {e}")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _list_triggers(
|
|
290
|
+
ctx: click.Context,
|
|
291
|
+
kind: _Kind,
|
|
292
|
+
all_projects: bool,
|
|
293
|
+
name: str,
|
|
294
|
+
coll: str,
|
|
295
|
+
):
|
|
296
|
+
verify_login_or_prompt(ctx)
|
|
297
|
+
# The pinned collection narrows the listing as it does everywhere else, but
|
|
298
|
+
# is not prompted for: with no collection the listing spans the project.
|
|
299
|
+
coll = coll or get_currently_pinned_object(ctx, "collection")
|
|
300
|
+
try:
|
|
301
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
302
|
+
spanning = resolve_all_projects(ctx, all_projects)
|
|
303
|
+
triggers, truncated = take(ctx, _triggers_of(server, kind, coll, name))
|
|
304
|
+
|
|
305
|
+
def _table():
|
|
306
|
+
table = Table(title=kind.title)
|
|
307
|
+
table.add_column("Function", style="cyan", no_wrap=True)
|
|
308
|
+
if spanning:
|
|
309
|
+
table.add_column("Project")
|
|
310
|
+
table.add_column("Collection")
|
|
311
|
+
table.add_column("Worker ID", no_wrap=True)
|
|
312
|
+
table.add_column("Status")
|
|
313
|
+
table.add_column("Started on", no_wrap=True)
|
|
314
|
+
table.add_column("Ended on", no_wrap=True)
|
|
315
|
+
for trigger in triggers:
|
|
316
|
+
row = [trigger.function.name]
|
|
317
|
+
if spanning:
|
|
318
|
+
row.append(trigger.project or "-")
|
|
319
|
+
row.extend([
|
|
320
|
+
trigger.collection.name,
|
|
321
|
+
trigger.id,
|
|
322
|
+
trigger.status,
|
|
323
|
+
beautify_time(trigger.started_on_str),
|
|
324
|
+
beautify_time(trigger.ended_on_str),
|
|
325
|
+
])
|
|
326
|
+
table.add_row(*row)
|
|
327
|
+
click.echo()
|
|
328
|
+
make_console().print(table)
|
|
329
|
+
click.echo(f"Number of {kind.plural}: {len(triggers)}")
|
|
330
|
+
click.echo()
|
|
331
|
+
|
|
332
|
+
# ``kwargs`` is the row the listing already returned; ``_data`` would
|
|
333
|
+
# re-fetch each worker one by one.
|
|
334
|
+
render(ctx, data=lambda: [t.kwargs for t in triggers], table=_table)
|
|
335
|
+
echo_more_results(ctx, truncated)
|
|
336
|
+
except Exception as e:
|
|
337
|
+
hint_common_solutions(ctx, e)
|
|
338
|
+
raise click.ClickException(f"Failed to list {kind.plural}: {e}")
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Tabsdata Inc.
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from typing import TYPE_CHECKING, List
|
|
8
|
+
|
|
9
|
+
import rich_click as click
|
|
10
|
+
from rich.table import Table
|
|
11
|
+
|
|
12
|
+
from tabsdatak.cli._registry import cli_command
|
|
13
|
+
from tabsdatak.cli.cli_utils import (
|
|
14
|
+
beautify_time,
|
|
15
|
+
collection_label,
|
|
16
|
+
echo_more_results,
|
|
17
|
+
format_option,
|
|
18
|
+
hint_common_solutions,
|
|
19
|
+
make_console,
|
|
20
|
+
max_result_option,
|
|
21
|
+
output_format,
|
|
22
|
+
render,
|
|
23
|
+
show_hint,
|
|
24
|
+
verify_login_or_prompt,
|
|
25
|
+
)
|
|
26
|
+
from tabsdatak.cli.td.execution_utils import (
|
|
27
|
+
confirm_cancel,
|
|
28
|
+
emit_worker_logs,
|
|
29
|
+
function_runs_table,
|
|
30
|
+
live_monitor,
|
|
31
|
+
obtain_list_trx_filters,
|
|
32
|
+
obtain_transaction_list,
|
|
33
|
+
pick_worker,
|
|
34
|
+
span_projects,
|
|
35
|
+
transactions_table,
|
|
36
|
+
workers_table,
|
|
37
|
+
)
|
|
38
|
+
from tabsdatak.sdk.status_utils.transaction import (
|
|
39
|
+
TRANSACTION_FINAL_STATUSES,
|
|
40
|
+
TRANSACTION_SUCCESSFUL_FINAL_STATUSES,
|
|
41
|
+
TRANSACTION_VALID_USER_PROVIDED_STATUSES,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if TYPE_CHECKING:
|
|
45
|
+
from tabsdatak.sdk.tabsdata_server import TabsdataServer
|
|
46
|
+
|
|
47
|
+
AT_OPTION_HELP = (
|
|
48
|
+
"If provided, only transactions started before that time will be shown. Must be "
|
|
49
|
+
"either a valid timestamp in the form of a unix timestamp (milliseconds since "
|
|
50
|
+
"epoch without a dot, e.g. '1750074554472') or a valid date-time format. "
|
|
51
|
+
"The valid "
|
|
52
|
+
"formats are 'YYYY-MM-DD', 'YYYY-MM-DDTHH', 'YYYY-MM-DDTHH:MM', "
|
|
53
|
+
"'YYYY-MM-DDTHH:MM:SS', and 'YYYY-MM-DDTHH:MM:SS.sss'. A 'Z' character can be "
|
|
54
|
+
"added at the end to indicate UTC time (e.g., '2023-10-01T12Z' or "
|
|
55
|
+
"'2023-10-01T12:00:00.000Z') or it can be omitted to indicate local "
|
|
56
|
+
"time (e.g., '2023-10-01T12' or '2023-10-01T12:00:00.000')."
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@cli_command
|
|
61
|
+
@click.group()
|
|
62
|
+
def trx():
|
|
63
|
+
"""Transaction management commands"""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@trx.command(name="list")
|
|
67
|
+
@click.option("--proj", type=str, help="Name of the project to filter transactions by.")
|
|
68
|
+
@click.option(
|
|
69
|
+
"--status",
|
|
70
|
+
type=str,
|
|
71
|
+
multiple=True,
|
|
72
|
+
help=(
|
|
73
|
+
"Filter transactions by status. The possible statuses are "
|
|
74
|
+
f"'{TRANSACTION_VALID_USER_PROVIDED_STATUSES}'. This field is "
|
|
75
|
+
"case-insensitive. "
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
@click.option(
|
|
79
|
+
"--coll", type=str, help="Name of the collection to filter transactions by."
|
|
80
|
+
)
|
|
81
|
+
@click.option("--plan", help="ID of the plan to filter transactions by.")
|
|
82
|
+
@click.option(
|
|
83
|
+
"--plan-name",
|
|
84
|
+
help=(
|
|
85
|
+
"A plan name wildcard to match. "
|
|
86
|
+
"For example, 'my_plan*' will match all plans "
|
|
87
|
+
"with names starting with 'my_plan'."
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
@click.option(
|
|
91
|
+
"--last",
|
|
92
|
+
is_flag=True,
|
|
93
|
+
help="If set, only the last transaction of the list will be shown.",
|
|
94
|
+
)
|
|
95
|
+
@click.option("--at", help=AT_OPTION_HELP, type=str)
|
|
96
|
+
@click.option(
|
|
97
|
+
"--monitor",
|
|
98
|
+
is_flag=True,
|
|
99
|
+
help=(
|
|
100
|
+
"If set, the command will monitor the listed transactions until they all "
|
|
101
|
+
"reach a final state."
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
@format_option
|
|
105
|
+
@max_result_option
|
|
106
|
+
@click.pass_context
|
|
107
|
+
def list_transactions(
|
|
108
|
+
ctx: click.Context,
|
|
109
|
+
proj: str,
|
|
110
|
+
status: List[str],
|
|
111
|
+
coll: str,
|
|
112
|
+
plan: str,
|
|
113
|
+
plan_name: str,
|
|
114
|
+
last: bool,
|
|
115
|
+
at: str,
|
|
116
|
+
monitor: bool,
|
|
117
|
+
):
|
|
118
|
+
"""List transactions across every project you can view."""
|
|
119
|
+
verify_login_or_prompt(ctx)
|
|
120
|
+
try:
|
|
121
|
+
request_filter = obtain_list_trx_filters(
|
|
122
|
+
status=status,
|
|
123
|
+
exe_name=plan_name,
|
|
124
|
+
execution_id=plan,
|
|
125
|
+
collection=coll,
|
|
126
|
+
at=at,
|
|
127
|
+
project=proj,
|
|
128
|
+
)
|
|
129
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
130
|
+
span_projects(server)
|
|
131
|
+
list_of_transactions, truncated = obtain_transaction_list(
|
|
132
|
+
ctx, server, request_filter, last
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
if output_format(ctx) != "table":
|
|
136
|
+
render(
|
|
137
|
+
ctx,
|
|
138
|
+
data=[t._data for t in list_of_transactions],
|
|
139
|
+
table=lambda: None,
|
|
140
|
+
)
|
|
141
|
+
echo_more_results(ctx, truncated)
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
if monitor:
|
|
145
|
+
click.echo("Waiting for the transactions to finish...")
|
|
146
|
+
list_of_transactions = live_monitor(
|
|
147
|
+
list_of_transactions,
|
|
148
|
+
lambda: obtain_transaction_list(ctx, server, request_filter, last)[0],
|
|
149
|
+
transactions_table,
|
|
150
|
+
lambda t: t.status in TRANSACTION_FINAL_STATUSES,
|
|
151
|
+
)
|
|
152
|
+
click.echo("Transactions finished.")
|
|
153
|
+
else:
|
|
154
|
+
click.echo()
|
|
155
|
+
console = make_console()
|
|
156
|
+
console.print(transactions_table(list_of_transactions))
|
|
157
|
+
echo_more_results(ctx, truncated)
|
|
158
|
+
click.echo()
|
|
159
|
+
if not all([
|
|
160
|
+
aux_trx.status in TRANSACTION_SUCCESSFUL_FINAL_STATUSES
|
|
161
|
+
for aux_trx in list_of_transactions
|
|
162
|
+
]):
|
|
163
|
+
show_hint(
|
|
164
|
+
ctx,
|
|
165
|
+
"If you want to explore why a transaction failed, run "
|
|
166
|
+
"'tdk trx logs --trx <TRANSACTION-ID>' to pick a worker and read "
|
|
167
|
+
"its logs, or 'tdk worker list --trx <TRANSACTION-ID>' to see the "
|
|
168
|
+
"workers.",
|
|
169
|
+
)
|
|
170
|
+
except Exception as e:
|
|
171
|
+
hint_common_solutions(ctx, e)
|
|
172
|
+
raise click.ClickException(f"Failed to list transactions: {e}")
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@trx.command()
|
|
176
|
+
@click.option("--trx", required=True, help="ID of the transaction to display.")
|
|
177
|
+
@format_option
|
|
178
|
+
@click.pass_context
|
|
179
|
+
def get(ctx: click.Context, trx: str):
|
|
180
|
+
"""
|
|
181
|
+
Display a transaction: its details plus its function runs and workers.
|
|
182
|
+
"""
|
|
183
|
+
verify_login_or_prompt(ctx)
|
|
184
|
+
try:
|
|
185
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
186
|
+
span_projects(server)
|
|
187
|
+
transaction = server.get_transaction(trx)
|
|
188
|
+
function_runs = server.list_function_runs(filter=f"transaction_id:eq:{trx}")
|
|
189
|
+
workers = server.list_workers(filter=f"transaction_id:eq:{trx}")
|
|
190
|
+
|
|
191
|
+
if output_format(ctx) != "table":
|
|
192
|
+
render(
|
|
193
|
+
ctx,
|
|
194
|
+
data={
|
|
195
|
+
"transaction": transaction._data,
|
|
196
|
+
"function_runs": [r._data for r in function_runs],
|
|
197
|
+
"workers": [w._data for w in workers],
|
|
198
|
+
},
|
|
199
|
+
table=lambda: None,
|
|
200
|
+
)
|
|
201
|
+
return
|
|
202
|
+
|
|
203
|
+
table = Table(title="Transaction")
|
|
204
|
+
table.add_column("Plan ID", no_wrap=True)
|
|
205
|
+
table.add_column("Project")
|
|
206
|
+
table.add_column("Collection")
|
|
207
|
+
table.add_column("Triggered on")
|
|
208
|
+
table.add_column("Triggered by")
|
|
209
|
+
table.add_column("Started on")
|
|
210
|
+
table.add_column("Ended on")
|
|
211
|
+
table.add_column("Status", no_wrap=True)
|
|
212
|
+
table.add_row(
|
|
213
|
+
transaction.execution.id,
|
|
214
|
+
transaction.project or "-",
|
|
215
|
+
collection_label(transaction),
|
|
216
|
+
beautify_time(transaction.triggered_on_str),
|
|
217
|
+
transaction.triggered_by,
|
|
218
|
+
beautify_time(transaction.started_on_str),
|
|
219
|
+
beautify_time(transaction.ended_on_str),
|
|
220
|
+
transaction.status,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
click.echo()
|
|
224
|
+
console = make_console()
|
|
225
|
+
console.print(table)
|
|
226
|
+
console.print(function_runs_table(function_runs))
|
|
227
|
+
console.print(workers_table(workers))
|
|
228
|
+
click.echo()
|
|
229
|
+
|
|
230
|
+
except Exception as e:
|
|
231
|
+
hint_common_solutions(ctx, e)
|
|
232
|
+
raise click.ClickException(f"Failed to display transaction: {e}")
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@trx.command()
|
|
236
|
+
@click.option("--trx", required=True, help="ID of the transaction to cancel.")
|
|
237
|
+
@click.option(
|
|
238
|
+
"--confirm",
|
|
239
|
+
help="Write 'cancel' to confirm cancellation. Will be prompted for it if "
|
|
240
|
+
"not provided.",
|
|
241
|
+
)
|
|
242
|
+
@click.pass_context
|
|
243
|
+
def cancel(ctx: click.Context, trx: str, confirm: str):
|
|
244
|
+
"""
|
|
245
|
+
Cancel a transaction and its non-committed function runs.
|
|
246
|
+
Canceled runs cannot be recovered.
|
|
247
|
+
"""
|
|
248
|
+
verify_login_or_prompt(ctx)
|
|
249
|
+
click.echo(f"Canceling transaction with ID '{trx}'")
|
|
250
|
+
click.echo("-" * 10)
|
|
251
|
+
confirm_cancel(ctx, confirm, f"transaction '{trx}'")
|
|
252
|
+
try:
|
|
253
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
254
|
+
server.cancel_transaction(trx)
|
|
255
|
+
click.echo("Transaction canceled successfully")
|
|
256
|
+
except Exception as e:
|
|
257
|
+
hint_common_solutions(ctx, e)
|
|
258
|
+
raise click.ClickException(f"Failed to cancel transaction: {e}")
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@trx.command()
|
|
262
|
+
@click.option("--trx", required=True, help="ID of the transaction to recover.")
|
|
263
|
+
@click.pass_context
|
|
264
|
+
def recover(ctx: click.Context, trx: str):
|
|
265
|
+
"""
|
|
266
|
+
Recover a transaction: its failed or on-hold function runs are
|
|
267
|
+
re-scheduled.
|
|
268
|
+
"""
|
|
269
|
+
verify_login_or_prompt(ctx)
|
|
270
|
+
click.echo(f"Recovering transaction with ID '{trx}'")
|
|
271
|
+
click.echo("-" * 10)
|
|
272
|
+
try:
|
|
273
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
274
|
+
server.recover_transaction(trx)
|
|
275
|
+
click.echo("Transaction recovered successfully")
|
|
276
|
+
except Exception as e:
|
|
277
|
+
hint_common_solutions(ctx, e)
|
|
278
|
+
raise click.ClickException(f"Failed to recover transaction: {e}")
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
@trx.command()
|
|
282
|
+
@click.option("--trx", required=True, help="ID of the transaction to monitor.")
|
|
283
|
+
@click.pass_context
|
|
284
|
+
def monitor(ctx: click.Context, trx: str):
|
|
285
|
+
"""
|
|
286
|
+
Monitor the execution of a transaction.
|
|
287
|
+
"""
|
|
288
|
+
verify_login_or_prompt(ctx)
|
|
289
|
+
try:
|
|
290
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
291
|
+
span_projects(server)
|
|
292
|
+
transaction = server.get_transaction(trx)
|
|
293
|
+
from tabsdatak.cli.td.fn_group import _monitor_execution_or_transaction
|
|
294
|
+
|
|
295
|
+
_monitor_execution_or_transaction(ctx, transaction=transaction)
|
|
296
|
+
except Exception as e:
|
|
297
|
+
hint_common_solutions(ctx, e)
|
|
298
|
+
raise click.ClickException(f"Failed to monitor transaction: {e}")
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@trx.command()
|
|
302
|
+
@click.option("--trx", required=True, help="ID of the transaction whose logs to show.")
|
|
303
|
+
@click.option(
|
|
304
|
+
"--file",
|
|
305
|
+
help=(
|
|
306
|
+
"Path of the file where the logs will be saved, or '-' to write them to "
|
|
307
|
+
"stdout. Any folders provided before the file must already exist."
|
|
308
|
+
),
|
|
309
|
+
)
|
|
310
|
+
@format_option
|
|
311
|
+
@click.pass_context
|
|
312
|
+
def logs(ctx: click.Context, trx: str, file: str):
|
|
313
|
+
"""
|
|
314
|
+
Show logs of one of the transaction's workers; when several ran, pick one
|
|
315
|
+
from the listing.
|
|
316
|
+
"""
|
|
317
|
+
verify_login_or_prompt(ctx)
|
|
318
|
+
try:
|
|
319
|
+
server: TabsdataServer = ctx.obj["tabsdataserver"]
|
|
320
|
+
span_projects(server)
|
|
321
|
+
target = pick_worker(
|
|
322
|
+
ctx, server, [f"transaction_id:eq:{trx}"], f"Transaction '{trx}'"
|
|
323
|
+
)
|
|
324
|
+
emit_worker_logs(ctx, server, target, file)
|
|
325
|
+
except click.exceptions.Exit:
|
|
326
|
+
raise
|
|
327
|
+
except Exception as e:
|
|
328
|
+
hint_common_solutions(ctx, e)
|
|
329
|
+
raise click.ClickException(f"Failed to show logs: {e}")
|