|
7 | 7 | from load_env import load_env_file
|
8 | 8 | from logger import create_log
|
9 | 9 |
|
10 |
| -#NEW_RELIC_LICENSE_KEY = Put license key here |
11 |
| -#ENVIRONMENT = Put environment here |
12 | 10 |
|
13 | 11 | if os.environ.get('NEW_RELIC_LICENSE_KEY', None):
|
14 | 12 | newrelic.agent.initialize(
|
15 | 13 | config_file='newrelic.ini',
|
16 | 14 | environment=os.environ.get('ENVIRONMENT', 'local')
|
17 |
| - ) |
| 15 | + ) |
| 16 | + |
18 | 17 |
|
19 | 18 | def main(args):
|
20 | 19 | logger = create_log(__name__)
|
21 | 20 |
|
22 | 21 | environment = args.environment
|
23 | 22 | process = args.process
|
24 |
| - procType = args.ingestType |
25 |
| - customFile = args.inputFile |
26 |
| - startDate = args.startDate |
27 |
| - singleRecord = args.singleRecord |
| 23 | + process_type = args.ingestType |
| 24 | + custom_file = args.inputFile |
| 25 | + start_date = args.startDate |
| 26 | + single_record = args.singleRecord |
28 | 27 | limit = args.limit
|
29 | 28 | offset = args.offset
|
30 | 29 | options = args.options
|
31 | 30 |
|
32 |
| - logger.info('Starting process {} in {}'.format(process, environment)) |
33 |
| - logger.debug('Process Args Type: {}, Limit: {}, Offset: {}, Date: {}, File: {}, Record: {}'.format( |
34 |
| - procType, limit, offset, startDate, customFile, singleRecord |
35 |
| - )) |
| 31 | + logger.info(f'Starting process {process} in {environment}') |
36 | 32 |
|
37 |
| - availableProcesses = registerProcesses() |
| 33 | + available_processes = register_processes() |
38 | 34 |
|
39 | 35 | try:
|
40 |
| - procClass = availableProcesses[process] |
41 |
| - processInstance = procClass( |
42 |
| - procType, customFile, startDate, singleRecord, limit, offset, options |
43 |
| - ) |
| 36 | + process_class = available_processes[process] |
| 37 | + |
| 38 | + process_instance = process_class(process_type, custom_file, start_date, single_record, limit, offset, options) |
44 | 39 | except:
|
45 | 40 | logger.exception(f'Failed to initialize process {process} in {environment}')
|
46 | 41 | return
|
47 | 42 |
|
48 |
| - if process in ( |
49 |
| - "APIProcess", # Covered by newrelic's automatic Flask integration |
50 |
| - "DevelopmentSetupProcess", |
51 |
| - "MigrationProcess", |
52 |
| - ): |
53 |
| - processInstance.runProcess() |
| 43 | + if process in ('APIProcess', 'DevelopmentSetupProcess', 'MigrationProcess'): |
| 44 | + process_instance.runProcess() |
54 | 45 | else:
|
55 | 46 | app = newrelic.agent.register_application(timeout=10.0)
|
56 |
| - with newrelic.agent.BackgroundTask(app, name=process): |
57 |
| - logger.info(f'Running process {process} in {environment}') |
58 |
| - processInstance.runProcess() |
| 47 | + |
| 48 | + with newrelic.agent.BackgroundTask(app, name=process_instance): |
| 49 | + process_instance.runProcess() |
59 | 50 |
|
60 | 51 |
|
61 |
| -def registerProcesses(): |
| 52 | +def register_processes(): |
62 | 53 | import processes
|
63 |
| - procs = inspect.getmembers(processes, inspect.isclass) |
64 |
| - return dict(procs) |
| 54 | + |
| 55 | + process_classes = inspect.getmembers(processes, inspect.isclass) |
| 56 | + |
| 57 | + return dict(process_classes) |
65 | 58 |
|
66 | 59 |
|
67 |
| -def createArgParser(): |
| 60 | +def create_arg_parser(): |
68 | 61 | parser = argparse.ArgumentParser(description='Run DCDW Data Ingest Jobs')
|
69 |
| - parser.add_argument('-p', '--process', required=True, |
70 |
| - help='The name of the process job to be run') |
71 |
| - parser.add_argument('-e', '--environment', required=True, |
72 |
| - help='Environment for deployment, sets env file to load') |
73 |
| - parser.add_argument('-i', '--ingestType', |
74 |
| - help='The interval to run the ingest over. Generally daily/complete/custom') |
75 |
| - parser.add_argument('-f', '--inputFile', |
76 |
| - help='Name of file to ingest. Ignored if -i custom is not set') |
77 |
| - parser.add_argument('-s', '--startDate', |
78 |
| - help='Start point for coverage period to query/process') |
79 |
| - parser.add_argument('-l', '--limit', |
80 |
| - help='Set overall limit for number of records imported in this process') |
81 |
| - parser.add_argument('-o', '--offset', |
82 |
| - help='Set start offset for current processed (for batched import process)') |
83 |
| - parser.add_argument('-r', '--singleRecord', |
84 |
| - help='Single record ID for ingesting an individual record') |
| 62 | + |
| 63 | + parser.add_argument('-p', '--process', required=True, help='The name of the process job to be run') |
| 64 | + parser.add_argument('-e', '--environment', required=True, help='Environment for deployment, sets env file to load') |
| 65 | + parser.add_argument('-i', '--ingestType', help='The interval to run the ingest over. Generally daily/complete/custom') |
| 66 | + parser.add_argument('-f', '--inputFile', help='Name of file to ingest. Ignored if -i custom is not set') |
| 67 | + parser.add_argument('-s', '--startDate', help='Start point for coverage period to query/process') |
| 68 | + parser.add_argument('-l', '--limit', help='Set overall limit for number of records imported in this process') |
| 69 | + parser.add_argument('-o', '--offset', help='Set start offset for current processed (for batched import process)') |
| 70 | + parser.add_argument('-r', '--singleRecord', help='Single record ID for ingesting an individual record') |
85 | 71 | parser.add_argument('options', nargs='*', help='Additional arguments')
|
86 | 72 |
|
87 | 73 | return parser
|
88 | 74 |
|
89 | 75 |
|
90 | 76 | if __name__ == '__main__':
|
91 |
| - parser = createArgParser() |
| 77 | + parser = create_arg_parser() |
92 | 78 | args = parser.parse_args()
|
93 | 79 |
|
94 | 80 | load_env_file(args.environment, './config/{}.yaml')
|
|
0 commit comments