diff --git a/locker_server/api/v1_0/user_rewards/views.py b/locker_server/api/v1_0/user_rewards/views.py index 6358fac..205510d 100644 --- a/locker_server/api/v1_0/user_rewards/views.py +++ b/locker_server/api/v1_0/user_rewards/views.py @@ -18,6 +18,7 @@ USER_MISSION_STATUS_UNDER_VERIFICATION, USER_MISSION_STATUS_REWARD_SENT, REWARD_TYPE_PREMIUM from locker_server.shared.constants.transactions import PLAN_TYPE_PM_FREE, PLAN_TYPE_PM_PREMIUM from locker_server.shared.error_responses.error import gen_error +from locker_server.shared.log.cylog import CyLog from locker_server.shared.utils.app import now from locker_server.shared.utils.factory import factory @@ -119,6 +120,13 @@ def completed(self, request, *args, **kwargs): if not mission_factory: return Response(status=status.HTTP_200_OK, data={"claim": False}) input_data = {"user": user, "user_identifier": user_identifier} + + if kwargs.get("pk") in ["capterra_rating_and_review", "clutch_rating_and_review", "g2_rating_and_review"]: + CyLog.info(**{ + "message": f"[+] Checking user reward: #{kwargs.get('pk')} - {input_data} by user #{user.user_id}", + "output": ["slack_reward_checking"] + }) + mission_check = mission_factory.check_mission_completion(input_data) answer = json.dumps(answer) diff --git a/locker_server/shared/log/config.py b/locker_server/shared/log/config.py index ce794a5..89e5d83 100644 --- a/locker_server/shared/log/config.py +++ b/locker_server/shared/log/config.py @@ -45,6 +45,12 @@ def filter(self, record): 'level': logging.DEBUG, 'filters': ['site_filter'] }, + 'slack_reward_checking': { + 'class': 'locker_server.shared.log.handlers.SlackRewardCheckingHandler', + 'formatter': 'medium', + 'level': logging.DEBUG, + 'filters': ['site_filter'] + }, 'console': { 'level': logging.DEBUG, 'class': 'logging.StreamHandler', @@ -76,6 +82,12 @@ def filter(self, record): 'propagate': True, 'filters': ['site_filter'] }, + 'slack_reward_checking_service': { + 'handlers': ['slack_reward_checking', ], + 'level': 'DEBUG', + 'propagate': True, + 'filters': ['site_filter'] + }, 'stdout_service': { 'level': 'DEBUG', 'handlers': ['console', ], diff --git a/locker_server/shared/log/cylog.py b/locker_server/shared/log/cylog.py index 8eebe35..c3adb9f 100644 --- a/locker_server/shared/log/cylog.py +++ b/locker_server/shared/log/cylog.py @@ -18,6 +18,8 @@ def create(cls, data): cls.log_to_slack(message, severity) elif output_type == "slack_new_users": cls.log_to_slack_new_users(message, severity) + elif output_type == "slack_reward_checking": + cls.log_to_slack_reward_checking(message, severity) elif output_type == "stdout": cls.log_to_screen(message, severity) @@ -50,6 +52,20 @@ def log_to_slack_new_users(message, severity): elif severity == "critical": logger.critical(message) + @staticmethod + def log_to_slack_reward_checking(message, severity): + logger = logging.getLogger('slack_reward_checking_service') + if severity == "debug": + logger.debug(message) + elif severity == "info": + logger.info(message) + elif severity == "warning": + logger.warning(message) + elif severity == "error": + logger.error(message) + elif severity == "critical": + logger.critical(message) + # Log to Screen @staticmethod def log_to_screen(message, severity): diff --git a/locker_server/shared/log/handlers.py b/locker_server/shared/log/handlers.py index 11c2514..6c84f69 100644 --- a/locker_server/shared/log/handlers.py +++ b/locker_server/shared/log/handlers.py @@ -36,3 +36,17 @@ def emit(self, record): ) except: print("Slack handler failed") + + +class SlackRewardCheckingHandler(logging.Handler): + def emit(self, record): + try: + record.exc_info = record.exc_text = None + content = {'text': self.format(record)} + requests.post( + url=settings.SLACK_WEBHOOK_REWARD_CHECKING, + json={"text": "```{}```".format(content['text'])}, + timeout=10 + ) + except Exception: + print("SlackRewardCheckingHandler failed") diff --git a/server_config/settings/dev.py b/server_config/settings/dev.py index 74af1f5..fbdd9da 100644 --- a/server_config/settings/dev.py +++ b/server_config/settings/dev.py @@ -248,6 +248,7 @@ SLACK_WEBHOOK_API_LOG = os.getenv("SLACK_WEBHOOK_API_LOG") SLACK_WEBHOOK_CRON_LOG = os.getenv("SLACK_WEBHOOK_CRON_LOG") SLACK_WEBHOOK_NEW_USERS = os.getenv("SLACK_WEBHOOK_NEW_USERS") + SLACK_WEBHOOK_REWARD_CHECKING = os.getenv("SLACK_WEBHOOK_REWARD_CHECKING") # Google sheet GOOGLE_SHEET_FEEDBACK_URL = os.getenv("GOOGLE_SHEET_FEEDBACK_URL")