def _authenticate_response(self, args): if args["response_type"] == CrowdAIEvents.Authentication["SUCCESS"]: self.session_key = args["session_token"] if not self.SUPPRESS_LOGGING_HELPERS: print(lh.success(CrowdAIEvents.Authentication["SUCCESS"], "Authentication Successful")) else: # TO-DO: Log authentication error if not self.SUPPRESS_LOGGING_HELPERS: print(lh.error(CrowdAIEvents.Authentication["ERROR"], args["message"])) self.disconnect() raise CrowdAIAuthenticationError(args["message"])
def on_execute_function_response(self, channel_name, payload={}): if payload == {}:# TODO: Critical This is a hacky fix. We need to find the exact reason why post-submit events are not in this format. payload = channel_name payload = json.loads(payload) job_state = payload['response_type'] job_id = payload['job_id'] sequence_no = payload["data_sequence_no"] #Sequence No being the index of the corresponding input data point in the parallel execution array message = payload["message"] if job_state == CrowdAIEvents.Job["ERROR"]: self.disconnect() raise CrowdAIExecuteFunctionError(payload["message"]) elif job_state == CrowdAIEvents.Job["ENQUEUED"]: job_event_messsage = lh.info_yellow(job_state, job_id); if self.PROGRESS_BAR: self.write_above_single_progress_bar(sequence_no, job_event_messsage) elif job_state == CrowdAIEvents.Job["RUNNING"]: job_event_messsage = lh.info_blue(job_state, job_id) if self.PROGRESS_BAR: self.write_above_single_progress_bar(sequence_no, job_event_messsage) if not self.AGGREGATED_PROGRESS_BAR: self.update_single_progress_bar_description(sequence_no, colored(job_id, 'green', attrs=['bold'])) elif job_state == CrowdAIEvents.Job["PROGRESS_UPDATE"]: self.update_progress_tracker(sequence_no, payload["data"]["percent_complete"]) if self.PROGRESS_BAR: if not self.AGGREGATED_PROGRESS_BAR: self.update_single_progress_bar_description(sequence_no, colored(job_id, 'green', attrs=['bold'])) elif job_state == CrowdAIEvents.Job["COMPLETE"]: self.update_progress_tracker(sequence_no, 100) job_event_messsage = lh.success(job_state, job_id) safe_job_event_messsage = job_event_messsage # When sequence number is less than 0, it is a JOB_COMPLETE event which is not associated with any # current jobs if sequence_no >= 0: safe_job_event_messsage = job_event_messsage + "\t OK" job_event_messsage += u"\t \U0001F37A " else: safe_job_event_messsage = job_event_messsage + "\t OK" job_event_messsage += u"\t \U0001F37A \U0001F37A \U0001F37A" if self.PROGRESS_BAR: try: self.write_above_single_progress_bar(sequence_no, job_event_messsage) except UnicodeEncodeError: # If the client doesnt have the relevant codecs for rendering this, # Then dont make a whole mess about it, and instead print the safe_job_event_messsage. self.write_above_single_progress_bar(sequence_no, safe_job_event_messsage) if not self.AGGREGATED_PROGRESS_BAR: self.update_single_progress_bar_description(sequence_no, colored(job_id, 'green', attrs=['bold'])) elif job_state == CrowdAIEvents.Job["INFO"]: job_event_messsage = lh.info(job_state, "("+job_id+") "+payload["message"]) if self.PROGRESS_BAR: self.write_above_single_progress_bar(sequence_no, job_event_messsage) elif job_state == CrowdAIEvents.Job["TIMEOUT"]: job_event_messsage = lh.error(job_state, "("+job_id+") "+payload["message"]) if self.PROGRESS_BAR: self.write_above_single_progress_bar(sequence_no, job_event_messsage) else: job_event_messsage = lh.error(job_state, "("+job_id+") "+str(payload["message"])) if self.PROGRESS_BAR: self.write_above_single_progress_bar(sequence_no, job_event_messsage) raise CrowdAIExecuteFunctionError("Malformed response from server. \ Please update your crowdai package, and if the problem still persists contact the server admins.\n")
def on_disconnect(self): if not self.SUPPRESS_LOGGING_HELPERS: print(lh.error(CrowdAIEvents.Connection["DISCONNECTED"], ""))
def on_disconnect(self): print(lh.error(CrowdAIEvents.Connection["DISCONNECTED"], ""))