Skip to content

Commit bc01aea

Browse files
committed
NRL-1268 auto trigger crawler
1 parent 27c717b commit bc01aea

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

terraform/account-wide-infrastructure/modules/glue/src/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
source_path=args["source_path"],
2020
target_path=args["target_path"],
2121
schema=logSchema,
22+
job_name=args["job_name"],
2223
partition_cols=partition_cols,
2324
transformations=[flatten_df, dtype_conversion],
2425
)

terraform/account-wide-infrastructure/modules/glue/src/pipeline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import boto3
12
from instances import GlueContextSingleton, LoggerSingleton
23

34

@@ -8,6 +9,7 @@ def __init__(
89
source_path,
910
target_path,
1011
schema,
12+
job_name,
1113
partition_cols=[],
1214
transformations=[],
1315
):
@@ -20,6 +22,12 @@ def __init__(
2022
self.schema = schema
2123
self.partition_cols = partition_cols
2224
self.transformations = transformations
25+
self.glue = boto3.client(
26+
service_name="glue",
27+
region_name="eu-west-2",
28+
endpoint_url="your-endpoint-url",
29+
)
30+
self.name_prefix = "-".join(job_name.split("-")[:3])
2331

2432
def run(self):
2533
"""Runs ETL"""
@@ -31,6 +39,8 @@ def run(self):
3139
self.logger.info("Data transformed successfully.")
3240
self.load(df)
3341
self.logger.info(f"Data loaded into {self.target_path}.")
42+
self.logger.info("Trigger glue crawler")
43+
self.trigger_crawler()
3444
except Exception as e:
3545
self.logger.error(f"ETL process failed: {e}")
3646
raise e
@@ -57,3 +67,9 @@ def load(self, dataframe):
5767
dataframe.write.mode("append").partitionBy(*self.partition_cols).parquet(
5868
self.target_path
5969
)
70+
71+
def trigger_crawler(self):
72+
try:
73+
self.glue.start_crawler(Name=f"{self.name_prefix}-log-crawler")
74+
except Exception as e:
75+
raise e

0 commit comments

Comments
 (0)