def run_report_with_data_blob(report_config, data, **kwargs): """ :param report_config: :return: """ report_function = resolve_function(report_config.function) report_result = success try: report_results = report_function(data, **kwargs) except Exception as e: report_results = [ header("Report %s failed to process with error %s" % (report_config.title, e)) ] report_result = failure try: parsed_report = parse_report_results(report_results) except Exception as e: parsed_report = "Report failed to parse %s with error %s\n" % ( report_config.title, str(e)) report_result = failure # We eithier print or email if report_config.output is "console": print(parsed_report) elif report_config.output is "email": send_mail_msg(parsed_report, subject=report_config.title) return report_result
def update_historical_prices_for_instrument_and_contract( contract_object, data, log=logger("")): """ Do a daily update for futures contract prices, using IB historical data :param contract_object: futuresContract :param data: data blob :param log: logger :return: None """ ib_prices = data.ib_futures_contract_price.get_prices_for_contract_object( contract_object) if len(ib_prices) == 0: log.warn("No IB prices found for %s" % str(contract_object)) return failure rows_added = data.arctic_futures_contract_price.update_prices_for_contract( contract_object, ib_prices, check_for_spike=True) if rows_added is data_error: ## SPIKE ## Need to email user about this as will need manually checking msg = "Spike found in prices for %s: need to manually check by running update_manual_check_historical_prices" % str( contract_object) log.warn(msg) try: send_mail_msg(msg, "Price Spike") except: log.warn("Couldn't send email about price spike") return success
def get_and_add_prices_for_frequency(data, log, contract_object, frequency="D"): broker_data_source = dataBroker(data) db_futures_prices = updatePrices(data) try: ib_prices = broker_data_source.get_prices_at_frequency_for_contract_object( contract_object, frequency) rows_added = db_futures_prices.update_prices_for_contract( contract_object, ib_prices, check_for_spike=True) if rows_added is data_error: ## SPIKE ## Need to email user about this as will need manually checking msg = "Spike found in prices for %s: need to manually check by running update_manual_check_historical_prices" % str( contract_object) log.warn(msg) try: send_mail_msg(msg, "Price Spike") except: log.warn("Couldn't send email about price spike for %s" % str(contract_object)) return failure log.msg("Added %d rows at frequency %s for %s" % (rows_added, frequency, str(contract_object))) return success except Exception as e: log.warn("Exception %s when getting data at frequency %s for %s" % (e, frequency, str(contract_object))) return failure
def send_email_and_record_date_or_store_on_fail( data, body: str, subject: str, email_is_report: bool = False ): try: send_mail_msg(body, subject) record_date_of_email_send(data, subject) data.log.msg("Sent email subject %s" % subject) except Exception as e: # problem sending emails will store instead data.log.msg( "Problem %s sending email subject %s, will store message instead" % (str(e), subject) ) store_message(data, body, subject, email_is_report=email_is_report)
def update_fx_prices_for_code(fx_code, data): broker_fx_source = dataBroker(data) db_fx_data = currencyData(data) new_fx_prices = broker_fx_source.get_fx_prices(fx_code) # returns fxPrices object rows_added = db_fx_data.update_fx_prices(fx_code, new_fx_prices, check_for_spike=True) if rows_added is data_error: msg = "Spike found in prices for %s: need to manually check by running update_manual_check_fx_prices" % str(fx_code) data.log.warn(msg) try: send_mail_msg(msg, "FX Price Spike") except: data.log.warn("Couldn't send email about price spike") return success
def update_fx_prices_for_code(fx_code, data): new_fx_prices = data.ib_fx_prices.get_fx_prices( fx_code) # returns fxPrices object rows_added = data.arctic_fx_prices.update_fx_prices(fx_code, new_fx_prices, check_for_spike=True) if rows_added is data_error: msg = "Spike found in prices for %s: need to manually check by running update_manual_check_fx_prices" % str( fx_code) data.log.warn(msg) try: send_mail_msg(msg, "FX Price Spike") except: data.log.warn("Couldn't send email about price spike") return success
def send_production_mail_msg(data, body, subject, report = False): """ Sends an email of particular text file with subject line After checking that we aren't sending too many emails per day """ send_email = can_we_send_this_email_now(data, subject, report = report) if send_email: try: send_mail_msg(body, subject) record_date_of_email_send(data, subject) return None except Exception as e: # problem sending emails will store instead data.log.msg("Problem %s sending email, will store message instead" % str(e)) ## won't send an email to avoid clogging up the inbox ## but will send one more to tell the user to check the logs of stored emails store_and_warn_email(data, body, subject, report=report)
def email_user(self, log_entry): try: send_mail_msg(str(log_entry), "*CRITICAL ERROR*") except: self.error("Couldn't email user")
def send_warning_email(subject): send_mail_msg("To reduce email load, won't send any more emails with this subject today. Use interactive_controls, retrieve emails to see stored messages", subject)
def email_user(self, log_entry): try: send_mail_msg(log_entry, "*CRITICAL ERROR*") except: self.log.warn("Couldn't email user")