Skip to content

Commit

Permalink
ctk tail: Add --interval option
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Dec 18, 2024
1 parent 428e75b commit a0aa293
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cratedb_toolkit/cmd/tail/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
@click.option("--format", "format_", type=str, required=False, help="Select output format. Default: log / jsonl")
@click.option("--follow", "-f", is_flag=True, required=False, help="Follow new records added, by polling the table")
@click.option("--interval", "-i", type=float, required=False, help="When following the tail, poll each N seconds. Default: 0.1")
@click.option("--verbose", is_flag=True, required=False, help="Turn on logging")
@click.option("--debug", is_flag=True, required=False, help="Turn on logging with debug level")
@click.argument("resource", nargs=-1, type=click.UNPROCESSED)
Expand All @@ -34,6 +35,7 @@ def cli(
lines: int,
format_: str,
follow: bool,
interval: float,
verbose: bool,
debug: bool,
):
Expand All @@ -48,5 +50,5 @@ def cli(
# TODO: Tail multiple tables.
if len(resource) > 1:
raise NotImplementedError("`ctk tail` currently implements tailing a single table only")
tt = TableTailer(db=adapter, resource=TableAddress.from_string(resource[0]), format=format_)
tt = TableTailer(db=adapter, resource=TableAddress.from_string(resource[0]), interval=interval, format=format_)
tt.start(lines=lines, follow=follow)
4 changes: 3 additions & 1 deletion cratedb_toolkit/cmd/tail/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TableTailer:

def __attrs_post_init__(self):
self.db.internal = True
if self.interval is None:
self.interval = 0.1
if not self.format:
if self.resource.fullname == "sys.jobs_log":
self.format = "log"
Expand Down Expand Up @@ -131,4 +133,4 @@ def start(self, lines: int = 10, follow: bool = False):
if not follow:
return result
offset += len(result)
time.sleep(self.interval)
time.sleep(t.cast(float, self.interval))

0 comments on commit a0aa293

Please sign in to comment.