MCPcopy Create free account
hub / github.com/adobe/Marinus / main

Function main

python3_cron_scripts/remove_expired_entries.py:157–339  ·  view source on GitHub ↗

Begin Main...

(logger=None)

Source from the content-addressed store, hash-verified

155
156
157def main(logger=None):
158 """
159 Begin Main...
160 """
161 if logger is None:
162 logger = LoggingUtil.create_log(__name__)
163
164 now = datetime.now()
165 print("Starting: " + str(now))
166 logger.info("Starting...")
167
168 mongo_connector = MongoConnector.MongoConnector()
169 all_dns_collection = mongo_connector.get_all_dns_connection()
170 dns_manager = DNSManager.DNSManager(mongo_connector)
171 GDNS = GoogleDNS.GoogleDNS()
172 ip_manager = IPManager.IPManager(mongo_connector)
173
174 jobs_manager = JobsManager.JobsManager(mongo_connector, "remove_expired_entries")
175 jobs_manager.record_job_start()
176
177 # zones = ZoneManager.get_distinct_zones(mongo_connector)
178
179 parser = argparse.ArgumentParser(description="Remove expired entries from Marinus")
180 parser.add_argument(
181 "--source",
182 required=False,
183 help="Only run the script for a specific data source",
184 )
185 args = parser.parse_args()
186
187 results = mongo_connector.perform_distinct(all_dns_collection, "sources.source")
188
189 sources_list = None
190 if args.source is not None and args.source != "":
191 if args.source not in results:
192 logger.error("FATAL: Unrecognized source value provided")
193 exit(1)
194
195 sources_list = [args.source]
196 else:
197 # The sources for which to remove expired entries
198 sources_list = results
199
200 sources = []
201 for source in sources_list:
202 temp = {}
203 temp["name"] = source
204 if "common_crawl" in source:
205 temp["diff"] = -4
206 else:
207 temp["diff"] = -2
208
209 sources.append(temp)
210
211 # Before completely removing old entries, make an attempt to see if they are still valid.
212 # Occasionally, a host name will still be valid but, for whatever reason, is no longer tracked by a source.
213 # Rather than throw away valid information, this will archive it.
214 for entry in sources:

Callers 1

Calls 14

record_job_startMethod · 0.95
fetch_DNS_recordsMethod · 0.95
record_job_completeMethod · 0.95
monthdeltaFunction · 0.85
get_lookup_intFunction · 0.85
insert_current_resultsFunction · 0.85
create_logMethod · 0.80
perform_distinctMethod · 0.80

Tested by

no test coverage detected