Skip to content

Commit

Permalink
Merge branch 'develop' into 'main'
Browse files Browse the repository at this point in the history
chore: Update log in user reward

See merge request locker/api-core!436
  • Loading branch information
khaitranquang committed May 4, 2024
2 parents 7d844df + 18e5c80 commit 476ad9f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions locker_server/api/v1_0/user_rewards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions locker_server/shared/log/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', ],
Expand Down
16 changes: 16 additions & 0 deletions locker_server/shared/log/cylog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions locker_server/shared/log/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions server_config/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 476ad9f

Please sign in to comment.