From a0aa293ba27452277223eb0968f9462e8d266cbf Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 17 Dec 2024 23:29:25 +0100 Subject: [PATCH] ctk tail: Add `--interval` option --- cratedb_toolkit/cmd/tail/cli.py | 4 +++- cratedb_toolkit/cmd/tail/main.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cratedb_toolkit/cmd/tail/cli.py b/cratedb_toolkit/cmd/tail/cli.py index 6b10e1d..16d9d1a 100644 --- a/cratedb_toolkit/cmd/tail/cli.py +++ b/cratedb_toolkit/cmd/tail/cli.py @@ -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) @@ -34,6 +35,7 @@ def cli( lines: int, format_: str, follow: bool, + interval: float, verbose: bool, debug: bool, ): @@ -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) diff --git a/cratedb_toolkit/cmd/tail/main.py b/cratedb_toolkit/cmd/tail/main.py index 081620c..f7fd9e7 100644 --- a/cratedb_toolkit/cmd/tail/main.py +++ b/cratedb_toolkit/cmd/tail/main.py @@ -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" @@ -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))