-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_engagement_db_to_rapid_pro.py
47 lines (35 loc) · 2.36 KB
/
sync_engagement_db_to_rapid_pro.py
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
import argparse
import importlib
import subprocess
from core_data_modules.logging import Logger
from engagement_database.data_models import HistoryEntryOrigin
from src.engagement_db_to_rapid_pro.engagement_db_to_rapid_pro import sync_engagement_db_to_rapid_pro
log = Logger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Syncs data from an engagement database to Rapid Pro")
parser.add_argument("--incremental-cache-path",
help="Path to a directory to use to cache results needed for incremental operation.")
parser.add_argument("user", help="Identifier of the user launching this program")
parser.add_argument("google_cloud_credentials_file_path", metavar="google-cloud-credentials-file-path",
help="Path to a Google Cloud service account credentials file to use to access the "
"credentials bucket")
parser.add_argument("configuration_module",
help="Configuration module to import e.g. 'configurations.test_config'. "
"This module must contain a PIPELINE_CONFIGURATION property")
args = parser.parse_args()
incremental_cache_path = args.incremental_cache_path
user = args.user
google_cloud_credentials_file_path = args.google_cloud_credentials_file_path
pipeline_config = importlib.import_module(args.configuration_module).PIPELINE_CONFIGURATION
pipeline = pipeline_config.pipeline_name
commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
project = subprocess.check_output(["git", "config", "--get", "remote.origin.url"]).decode().strip()
HistoryEntryOrigin.set_defaults(user, project, pipeline, commit)
if pipeline_config.rapid_pro_target is None:
log.info(f"No rapid_pro_target provided in configuration; exiting")
exit(0)
uuid_table = pipeline_config.uuid_table.init_uuid_table_client(google_cloud_credentials_file_path)
engagement_db = pipeline_config.engagement_database.init_engagement_db_client(google_cloud_credentials_file_path)
rapid_pro = pipeline_config.rapid_pro_target.rapid_pro.init_rapid_pro_client(google_cloud_credentials_file_path)
sync_config = pipeline_config.rapid_pro_target.sync_config
sync_engagement_db_to_rapid_pro(engagement_db, rapid_pro, uuid_table, sync_config, incremental_cache_path)