def process_subscription(subscription, live): is_ready_to_be_processed_db = subscription.get_is_ready_to_be_processed_from_db( ) logger.info(" - subscription %d", subscription.pk) if is_ready_to_be_processed_db: logger.info(" -- (ready via db) ") are_we_past_next_valid_timestamp = subscription.get_are_we_past_next_valid_timestamp( ) # FOR DEBUGGING if not live: is_ready_to_be_processed_web3 = subscription.get_is_subscription_ready_from_web3( ) is_active_web3 = subscription.get_is_active_from_web3() signer = subscription.get_subscription_signer_from_web3() logger.info(" --- DEBUG INFO") logger.info( " --- %s, %s, %s, %s", are_we_past_next_valid_timestamp, is_ready_to_be_processed_web3, is_active_web3, signer, ) if not are_we_past_next_valid_timestamp: logger.info(" -- ( NOT ready via web3) ") else: logger.info(" -- (ready via web3) ") status = 'failure' txid = None error = "" try: if live: logger.info(" -- *executing* ") while not has_tx_mined(subscription.new_approve_tx_id, subscription.grant.network): time.sleep(SLEEP_TIME) logger.info(f" -- *waiting {SLEEP_TIME} seconds*") txid = subscription.do_execute_subscription_via_web3() logger.info(" -- *waiting for mine* (txid %s) ", txid) while not has_tx_mined(txid, subscription.grant.network): time.sleep(SLEEP_TIME) logger.info(f" -- *waiting {SLEEP_TIME} seconds*") status, __ = get_tx_status(txid, subscription.grant.network, timezone.now()) if status != 'success': error = f"tx status from RPC is {status} not success, txid: {txid}" else: logger.info(" -- *not live, not executing* ") except Exception as e: error = str(e) logger.info(" -- *not live, not executing* ") logger.info(" -- *mined* (status: %s / error: %s) ", status, error) was_success = status == 'success' if live: if not was_success: logger.warning('subscription processing failed') subscription.error = True error_comments = f"{error}\n\ndebug info: {subscription.get_debug_info()}" subscription.subminer_comments = error_comments subscription.save() warn_subscription_failed(subscription) else: logger.info('subscription processing successful') subscription.successful_contribution(txid) subscription.save()
def process_subscription(subscription, live): is_ready_to_be_processed_db = subscription.get_is_ready_to_be_processed_from_db() logger.info(" - subscription %d", subscription.pk) if is_ready_to_be_processed_db: logger.info(" -- (ready via db) ") are_we_past_next_valid_timestamp = subscription.get_are_we_past_next_valid_timestamp() has_approve_tx_mined = has_tx_mined(subscription.new_approve_tx_id, subscription.grant.network) # FOR DEBUGGING if not live: is_ready_to_be_processed_web3 = subscription.get_are_we_past_next_valid_timestamp() is_active_web3 = subscription.get_is_active_from_web3() signer = subscription.get_subscription_signer_from_web3() logger.info(" --- DEBUG INFO") logger.info( " --- %s, %s, %s, %s", are_we_past_next_valid_timestamp, is_ready_to_be_processed_web3, is_active_web3, signer, ) if not are_we_past_next_valid_timestamp: logger.info(f" -- ( NOT ready via web3, will be ready on {subscription.get_next_valid_timestamp()}) ") elif not has_approve_tx_mined: logger.info(f" -- ( NOT ready via approve tx, will be ready when {subscription.new_approve_tx_id} mines) ") else: if subscription.contributor_signature == "onetime": subscription.error = True subscription.subminer_comments = "One time subscription" subscription.save() logger.info('skipping one time subscription: %s' % subscription.id) return web3_hash_arguments = subscription.get_subscription_hash_arguments() if web3_hash_arguments['periodSeconds'] < METATX_FREE_INTERVAL_SECONDS and web3_hash_arguments['gasPrice'] <= METATX_GAS_PRICE_THRESHOLD: subscription.error = True subscription.subminer_comments = "Gas price was too low to process" subscription.save() warn_subscription_failed(subscription) return logger.info(" -- (ready via web3) ") status = 'failure' txid = None error = "" try: if live: logger.info(" -- *executing* ") txid = subscription.do_execute_subscription_via_web3() logger.info(" -- *waiting for mine* (txid %s) ", txid) override = False counter = 0 while not has_tx_mined(txid, subscription.grant.network) and not override: time.sleep(SLEEP_TIME) logger.info(f" -- *waiting {SLEEP_TIME} seconds for {txid} to mine*") counter += 1 if counter > MAX_COUNTER: override = True # force the subminer to continue on; this tx is taking too long. # an admin will have to look at this later and determine what went wrong # KO 2019/02/06 status, __ = get_tx_status(txid, subscription.grant.network, timezone.now()) if status != 'success': error = f"tx status from RPC is {status} not success, txid: {txid}" else: logger.info(" -- *not live, not executing* ") except Exception as e: error = str(e) logger.info(" -- *not live, not executing* ") logger.info(" -- *mined* (status: %s / error: %s) ", status, error) was_success = status == 'success' if live: if not was_success: logger.warning('subscription processing failed') subscription.error = True error_comments = f"{error}\n\ndebug info: {subscription.get_debug_info()}" subscription.subminer_comments = error_comments subscription.save() grant = subscription.grant grant.updateActiveSubscriptions() grant.save() warn_subscription_failed(subscription) else: logger.info('subscription processing successful') subscription.successful_contribution(txid) subscription.save()
def process_subscription(subscription, live): is_ready_to_be_processed_db = subscription.get_is_ready_to_be_processed_from_db( ) logger.info(" - subscription %d", subscription.pk) if is_ready_to_be_processed_db: logger.info(" -- (ready via db) ") are_we_past_next_valid_timestamp = subscription.get_are_we_past_next_valid_timestamp( ) # FOR DEBUGGING if not live: is_ready_to_be_processed_web3 = subscription.get_is_subscription_ready_from_web3( ) is_active_web3 = subscription.get_is_active_from_web3() signer = subscription.get_subscription_signer_from_web3() logger.info(" --- DEBUG INFO") logger.info( " --- %s, %s, %s, %s", are_we_past_next_valid_timestamp, is_ready_to_be_processed_web3, is_active_web3, signer, ) if not are_we_past_next_valid_timestamp: logger.info( f" -- ( NOT ready via web3, will be ready on {subscription.get_next_valid_timestamp()}) " ) else: logger.info(" -- (ready via web3) ") status = 'failure' txid = None error = "" try: if live: logger.info(" -- *executing* ") counter = 0 while not has_tx_mined(subscription.new_approve_tx_id, subscription.grant.network): time.sleep(SLEEP_TIME) logger.info( f" -- *waiting {SLEEP_TIME} seconds for {subscription.new_approve_tx_id} to mine*" ) counter += 1 if counter > MAX_COUNTER: raise Exception( f"waited more than {MAX_COUNTER} times for tx to mine" ) txid = subscription.do_execute_subscription_via_web3() logger.info(" -- *waiting for mine* (txid %s) ", txid) override = False counter = 0 while not has_tx_mined( txid, subscription.grant.network) and not override: time.sleep(SLEEP_TIME) logger.info( f" -- *waiting {SLEEP_TIME} seconds for {txid} to mine*" ) counter += 1 if counter > MAX_COUNTER: override = True # force the subminer to continue on; this tx is taking too long. # an admin will have to look at this later and determine what went wrong # KO 2019/02/06 status, __ = get_tx_status(txid, subscription.grant.network, timezone.now()) if status != 'success': error = f"tx status from RPC is {status} not success, txid: {txid}" else: logger.info(" -- *not live, not executing* ") except Exception as e: error = str(e) logger.info(" -- *not live, not executing* ") logger.info(" -- *mined* (status: %s / error: %s) ", status, error) was_success = status == 'success' if live: if not was_success: logger.warning('subscription processing failed') subscription.error = True error_comments = f"{error}\n\ndebug info: {subscription.get_debug_info()}" subscription.subminer_comments = error_comments subscription.save() warn_subscription_failed(subscription) else: logger.info('subscription processing successful') subscription.successful_contribution(txid) subscription.save()