-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_data_update.py
More file actions
59 lines (45 loc) · 1.84 KB
/
Copy pathrun_data_update.py
File metadata and controls
59 lines (45 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Run the most recent partition for every job in the gcp_usage_metrics dagster repository.
This script runs daily in the load-metrics Github Action.
Note: Eventually this script should be deprecated in
favor of having a long running dagster instance handle
schedules and job launching.
"""
import logging
import os
import click
import coloredlogs
from usage_metrics.etl import defs
@click.command(
context_settings={"help_option_names": ["-h", "--help"]},
)
@click.option("-p", "--partition", type=str, default=None)
def main(partition: str | None):
"""Load most recent partitions of data to Google Cloud Storage."""
usage_metrics_logger = logging.getLogger("usage_metrics")
log_format = "%(asctime)s [%(levelname)8s] %(name)s:%(lineno)s %(message)s"
coloredlogs.install(fmt=log_format, level="INFO", logger=usage_metrics_logger)
usage_metrics_logger.info(
f"""Saving to {os.getenv("METRICS_PROD_ENV", "local")} storage."""
)
# Run the partitioned metrics
job = defs.get_job_def(name="all_partitioned_metrics_etl")
# Get last complete weekly partition
if partition:
assert partition in job.partitions_def.get_partition_keys(), (
f"{partition} isn't a valid partition. Valid partitions are: {job.partitions_def.get_partition_keys()}"
)
else:
partition = max(job.partitions_def.get_partition_keys())
# Run the jobs
usage_metrics_logger.info(
f"""{job.name}: Processing partitioned data from the week of {partition}."""
)
job.execute_in_process(partition_key=partition)
# Run the non-partitioned metrics
usage_metrics_logger.info(
f"""{job.name}: Processing the most recent non-partitioned data."""
)
job = defs.get_job_def(name="all_nonpartitioned_metrics_etl")
job.execute_in_process()
if __name__ == "__main__":
main()