feat: add --count option to scan command for limiting records scanned
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -15,8 +15,9 @@ def main(ctx, config):
|
|||||||
|
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
|
@click.option("--count", default=0, type=int, help="Number of records to scan (0 = full table)")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def scan(ctx):
|
def scan(ctx, count):
|
||||||
cfg = load_config(ctx.obj["config_path"])
|
cfg = load_config(ctx.obj["config_path"])
|
||||||
from order_bak.scan import scan_orders
|
from order_bak.scan import scan_orders
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ def scan(ctx):
|
|||||||
page_size=cfg.scan_page_size,
|
page_size=cfg.scan_page_size,
|
||||||
delay_ms=cfg.scan_delay_ms,
|
delay_ms=cfg.scan_delay_ms,
|
||||||
scan_dir=cfg.scan_dir,
|
scan_dir=cfg.scan_dir,
|
||||||
|
limit=count,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ def scan_orders(
|
|||||||
page_size: int,
|
page_size: int,
|
||||||
delay_ms: int,
|
delay_ms: int,
|
||||||
scan_dir: Path,
|
scan_dir: Path,
|
||||||
|
limit: int = 0,
|
||||||
) -> Path:
|
) -> Path:
|
||||||
table = TableClient.from_connection_string(connection_string, table_name="order")
|
table = TableClient.from_connection_string(connection_string, table_name="order")
|
||||||
scan_dir.mkdir(parents=True, exist_ok=True)
|
scan_dir.mkdir(parents=True, exist_ok=True)
|
||||||
@@ -32,6 +33,11 @@ def scan_orders(
|
|||||||
for entity in page:
|
for entity in page:
|
||||||
writer.writerow(entity_to_row(entity))
|
writer.writerow(entity_to_row(entity))
|
||||||
total_scanned += 1
|
total_scanned += 1
|
||||||
|
if limit > 0 and total_scanned >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
|
if limit > 0 and total_scanned >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
if delay_ms > 0:
|
if delay_ms > 0:
|
||||||
time.sleep(delay_ms / 1000.0)
|
time.sleep(delay_ms / 1000.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user