-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polling機能の追加 #2
Polling機能の追加 #2
Conversation
@@ -0,0 +1,20 @@ | |||
# -*- coding:utf-8 -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/management/commands 以下にBaseCommandを継承したクラスを作ると自作コマンドを登録できる
https://docs.djangoproject.com/en/4.1/howto/custom-management-commands/
help = 'polling sqs and execute score_evaluations' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('interval', nargs='?', type=int, default=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ポーリングの際、sqsにメッセージがなかった時はinterval秒だけ次のメッセージ取得まで待つ
faultは60秒で任意の秒数を設定可能
print("start polling") | ||
while True: | ||
_eval = self.execute() | ||
if _eval is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqsにメッセージがなかった場合はNoneが返される
メッセージが取得できた場合には、評価が終了するとすぐに次のメッセージ取得を試行する
} | ||
return response | ||
|
||
message = str(msg.SerializeToString()) | ||
message = str(base64.b64encode(msg.SerializeToString())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api-gateway経由のリクエストも一度base64decodeしてパースした後、
シリアライズしたメッセージをbase64encodeしてからsqsに登録する。
@@ -33,13 +33,13 @@ def lambda_handler(event: dict, context): | |||
"body": response, | |||
"code": 200 | |||
} | |||
except: | |||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tryで発生したエラーをすべてキャッチしてレスポンスに返す
コンテナ内でpollingがうまく動くことを確認した
|
sqsを指定秒数ごとにポーリングする