|
11 | 11 | import sys
|
12 | 12 | import time
|
13 | 13 | from dataclasses import dataclass
|
14 |
| -from datetime import datetime |
| 14 | +from datetime import datetime, timezone |
15 | 15 | from enum import IntEnum
|
16 | 16 | from typing import Optional, Any
|
17 | 17 |
|
@@ -413,7 +413,7 @@ def get_comments(
|
413 | 413 | return comments
|
414 | 414 |
|
415 | 415 |
|
416 |
| -def get_last_run_timestamp(bq_client: bigquery.Client) -> Optional[int]: |
| 416 | +def get_last_run_timestamp(bq_client: bigquery.Client) -> Optional[datetime]: |
417 | 417 | """Get the timestamp of the most recently added entry in BigQuery.
|
418 | 418 |
|
419 | 419 | See https://github.com/googleapis/python-bigquery/blob/main/samples/query_script.py
|
@@ -470,17 +470,27 @@ def get_time_queries(now: datetime, bq_client: bigquery.Client) -> list:
|
470 | 470 | Dont take the revisions created before the last run
|
471 | 471 | """
|
472 | 472 | queries = [
|
473 |
| - DiffDb.Revision.dateCreated < now.timestamp(), |
474 |
| - DiffDb.Revision.dateModified < now.timestamp(), |
| 473 | + or_( |
| 474 | + DiffDb.Revision.dateCreated < now.timestamp(), |
| 475 | + DiffDb.Revision.dateModified < now.timestamp(), |
| 476 | + ), |
475 | 477 | ]
|
476 |
| - last_run_timestamp = get_last_run_timestamp(bq_client) |
| 478 | + last_run_datetime = get_last_run_timestamp(bq_client) |
| 479 | + |
| 480 | + if last_run_datetime: |
| 481 | + last_run_datetime = last_run_datetime.replace(tzinfo=timezone.utc) |
| 482 | + last_run_timestamp = last_run_datetime.timestamp() |
| 483 | + |
| 484 | + logging.info( |
| 485 | + f"Using {last_run_datetime} as the last run date ({last_run_timestamp})." |
| 486 | + ) |
477 | 487 |
|
478 |
| - if last_run_timestamp: |
479 |
| - logging.info(f"Using {last_run_timestamp} as the last run timestamp.") |
480 | 488 | queries.extend(
|
481 | 489 | [
|
482 |
| - DiffDb.Revision.dateCreated > last_run_timestamp, |
483 |
| - DiffDb.Revision.dateModified > last_run_timestamp, |
| 490 | + or_( |
| 491 | + DiffDb.Revision.dateCreated > last_run_timestamp, |
| 492 | + DiffDb.Revision.dateModified > last_run_timestamp, |
| 493 | + ), |
484 | 494 | ]
|
485 | 495 | )
|
486 | 496 | else:
|
|
0 commit comments