Skip to content

Commit

Permalink
Enable .env config for data import
Browse files Browse the repository at this point in the history
  • Loading branch information
dborowiecki committed Jun 23, 2024
1 parent 40d9c35 commit d6711c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ cython_debug/
sigeca_data_export_microservice/config.json
sigeca_data_import_microservice/config.json
sigeca_data_import_microservice/mocked_facilities.json
sigeca_data_import_microservice/private_key
sigeca_data_import_microservice/private_key
*/settings.env
29 changes: 21 additions & 8 deletions sigeca_data_import_microservice/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
)
from app.infrastructure.jdbc_reader import JDBCReader
import argparse
from dotenv import dotenv_values

def load_config(config_path):
with open(config_path, "r") as config_file:
config = json.load(config_file)
return config


def load_config(from_env=False):
if from_env:
config = dotenv_values('./settings.env')
if 'sigeca_import_config' not in config.keys():
raise KeyError("Provided settings.env missing `sigeca_import_config` key.")
return json.loads(config['sigeca_import_config'])
else:
with open('config.json', "r") as config_file:
config = json.load(config_file)
return config


def _run_scheduler(sync_service, sync_interval_minutes):
Expand All @@ -34,8 +43,14 @@ def _run_scheduler(sync_service, sync_interval_minutes):


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Data synchronization service")
parser.add_argument("--run-mode", choices=["continuous", "one-time"], required=True, help="Run mode: 'continuous' to start the scheduler or 'one-time' to execute one-time integration")
parser.add_argument("--env-config", required=False, action='store_true', help="Env Config: use stringified config comming form env instead of .json file")
args = parser.parse_args()

logging.basicConfig(level=logging.INFO)
config = load_config("./config.json")

config = load_config(args.env_config)
engine = get_engine(config["database"])

lmis_client = OpenLmisApiClient(config["open_lmis_api"])
Expand All @@ -57,9 +72,7 @@ def _run_scheduler(sync_service, sync_interval_minutes):
jdbc_reader.setup_ssh_tunnel()
lmis_client.login()

parser = argparse.ArgumentParser(description="Data synchronization service")
parser.add_argument("--run-mode", choices=["continuous", "one-time"], required=True, help="Run mode: 'continuous' to start the scheduler or 'one-time' to execute one-time integration")
args = parser.parse_args()


if args.run_mode == "continuous":
sync_interval_minutes = config["sync"]["interval_minutes"]
Expand Down

0 comments on commit d6711c6

Please sign in to comment.