Skip to content

Commit

Permalink
Add PingResource for ping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AmadeusGB committed Oct 25, 2024
1 parent db86e99 commit b6d2ee6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion explorer-api/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@
app.add_route('/deeper/cross_chain_requests', polkascan.WithdrawalRequestResource())
app.add_route('/deeper/has_new_cross_chain', polkascan.NewEventCheckResource())
app.add_route('/deeper/bridge_deeper_to_other', polkascan.DeeperToOtherBlockchainResource())
app.add_route('/deeper/bridge_other_to_deeper', polkascan.OtherToDeeperBlockchainResource())
app.add_route('/deeper/bridge_other_to_deeper', polkascan.OtherToDeeperBlockchainResource())
app.add_route('/ping', polkascan.PingResource())
20 changes: 20 additions & 0 deletions explorer-api/app/resources/polkascan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2429,3 +2429,23 @@ def on_get(self, req, resp):

# 设置响应数据
resp.media = data

class PingResource(BaseResource):
def on_get(self, req, resp):
try:
logging.warning('PingResource: received ping request')
resp.status = falcon.HTTP_200
resp.media = {
'message': 'pong',
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'status': 'success'
}
logging.warning('PingResource: responded with pong')
except Exception as e:
logging.warning(f'PingResource error: {str(e)}')
resp.status = falcon.HTTP_500
resp.media = {
'message': 'error',
'error': str(e),
'status': 'failed'
}

0 comments on commit b6d2ee6

Please sign in to comment.