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

Class APIHelper

python3_cron_scripts/libs3/APIHelper.py:18–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17
18class APIHelper(object):
19 _logger = logging.getLogger(__name__)
20
21 MC = MongoConnector.MongoConnector()
22
23 INCORRECT_RESPONSE_JSON_ALLOWED = 20
24
25 _allowed_giveup_failures = 20
26
27 def handle_api_error(self, err, jobs_reference):
28 """
29 Exits the script execution post setting the status in database.
30 :param err: Exception causing script exit.
31 :param jobs_reference: A string with the job name or the JobsManager for the exiting script.
32 """
33 self._logger.error("FATAL: " + str(err))
34 self._logger.error("Exiting script execution.")
35 if isinstance(jobs_reference, str):
36 jobs_manager = JobsManager.JobsManager(self.MC, jobs_reference)
37 jobs_manager.record_job_error(str(err))
38 else:
39 jobs_reference.record_job_error(str(err))
40
41 exit(1)
42
43 def connection_error_retry(self, details):
44 self._logger.error(
45 "Connection Error encountered. Retrying in {wait:0.1f} seconds".format(
46 **details
47 )
48 )
49
50 def backoff_giveup(self, details):
51 """
52 This is a temporary addition to see how often the system calls this function.
53 It will need tuning.
54 """
55 self._logger.error(
56 "FATAL: Calling function {target} could not connect with args {args} and kwargs "
57 "{kwargs}".format(**details)
58 )
59
60 # This is temporary addition that will require tuning to get the correct threshold
61 self._allowed_giveup_failures = self._allowed_giveup_failures - 1
62 if self._allowed_giveup_failures <= 0:
63 self._logger.error("FATAL: Number of allowed failures reached. Exiting.")
64 exit(1)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected