empty uri

This commit is contained in:
rimu 2024-05-22 06:29:28 +12:00
parent f099380f72
commit b911967168
2 changed files with 29 additions and 23 deletions

View file

@ -94,20 +94,25 @@ def post_request(uri: str, body: dict | None, private_key: str, key_id: str, con
log.activity_json=json.dumps(body) log.activity_json=json.dumps(body)
db.session.add(log) db.session.add(log)
db.session.commit() db.session.commit()
try:
result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout) if uri is None or uri == '':
if result.status_code != 200 and result.status_code != 202:
log.result = 'failure'
log.exception_message += f' Response status code was {result.status_code}'
current_app.logger.error('Response code for post attempt was ' +
str(result.status_code) + ' ' + result.text)
log.exception_message += uri
if result.status_code == 202:
log.exception_message += ' 202'
except Exception as e:
log.result = 'failure' log.result = 'failure'
log.exception_message='could not send:' + str(e) log.exception_message = 'empty uri'
current_app.logger.error(f'Exception while sending post to {uri}') else:
try:
result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout)
if result.status_code != 200 and result.status_code != 202:
log.result = 'failure'
log.exception_message += f' Response status code was {result.status_code}'
current_app.logger.error('Response code for post attempt was ' +
str(result.status_code) + ' ' + result.text)
log.exception_message += uri
if result.status_code == 202:
log.exception_message += ' 202'
except Exception as e:
log.result = 'failure'
log.exception_message='could not send:' + str(e)
current_app.logger.error(f'Exception while sending post to {uri}')
if log.result == 'processing': if log.result == 'processing':
log.result = 'success' log.result = 'success'
db.session.commit() db.session.commit()

View file

@ -689,16 +689,17 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload):
community = Community.query.get(community_id) community = Community.query.get(community_id)
if community: if community:
instance = Instance.query.get(instance_id) instance = Instance.query.get(instance_id)
if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'): if instance.inbox:
instance.last_successful_send = utcnow() if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'):
instance.failures = 0 instance.last_successful_send = utcnow()
else: instance.failures = 0
instance.failures += 1 else:
instance.most_recent_attempt = utcnow() instance.failures += 1
instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4) instance.most_recent_attempt = utcnow()
if instance.failures > 10: instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4)
instance.dormant = True if instance.failures > 10:
db.session.commit() instance.dormant = True
db.session.commit()
def community_in_list(community_id, community_list): def community_in_list(community_id, community_list):