aboutsummaryrefslogtreecommitdiff
path: root/jb/managers
diff options
context:
space:
mode:
authorMax Nanis2026-09-10 01:00:39 -0700
committerMax Nanis2026-09-10 01:00:39 -0700
commit4dca7296742b607e74f16e2f6484c51163a41ace (patch)
tree0839c16d0905deb587d3ee25ff93fd3ccf7eeeb6 /jb/managers
parent832aecaddce80e312095ecdb572d7756eb9df5e9 (diff)
downloadamt-jb-4dca7296742b607e74f16e2f6484c51163a41ace.tar.gz
amt-jb-4dca7296742b607e74f16e2f6484c51163a41ace.zip
using model_validator on GRLSettings. Allows null default values, then to asser them on load. Required so pydantic_settings can be loaded in tests without params
Diffstat (limited to 'jb/managers')
-rw-r--r--jb/managers/amt.py16
-rw-r--r--jb/managers/email_manager.py7
-rw-r--r--jb/managers/gr_api.py12
-rw-r--r--jb/managers/hit.py2
4 files changed, 21 insertions, 16 deletions
diff --git a/jb/managers/amt.py b/jb/managers/amt.py
index e2c7e90..2411080 100644
--- a/jb/managers/amt.py
+++ b/jb/managers/amt.py
@@ -1,4 +1,3 @@
-import logging
from datetime import datetime, timezone
from typing import Any
@@ -15,6 +14,7 @@ from mypy_boto3_mturk.type_defs import (
from pydantic import ValidationError
from jb.config import TOPIC_ARN
+from jb.decorators import LOG
from jb.models import AMTAccount
from jb.models.assignment import Assignment
from jb.models.bonus import Bonus
@@ -78,7 +78,7 @@ class AMTManager:
return HitStatus.Disposed
else:
- logging.warning(msg)
+ LOG.warning(msg)
return HitStatus.Unassignable
return res.status
@@ -137,7 +137,7 @@ class AMTManager:
# Baddies have been known to submit assignments with purposely
# malformed "answer" (xml) section, which will raise
# a pydantic validation error. Try to parse again with no Answer.
- logging.exception(e)
+ LOG.exception(e)
ass_res["Answer"] = None
# If it wasn't the Answer that caused the ValidationError, it'll raise again
assignment = Assignment.from_amt_get_assignment(ass_res)
@@ -152,7 +152,7 @@ class AMTManager:
try:
return self.get_assignment(amt_assignment_id=amt_assignment_id)
except botocore.exceptions.ClientError as e:
- logging.warning(e)
+ LOG.warning(e)
error_code = e.response["Error"]["Code"]
error_msg = e.response["Error"]["Message"]
if error_code == "RequestError" and expected_err_msg in error_msg:
@@ -170,7 +170,7 @@ class AMTManager:
)
except botocore.exceptions.ClientError as e:
- logging.warning(e)
+ LOG.warning(e)
return None
def approve_assignment_if_possible(
@@ -189,7 +189,7 @@ class AMTManager:
)
except botocore.exceptions.ClientError as e:
- logging.warning(e)
+ LOG.warning(e)
return None
def update_hit_review_status(self, amt_hit_id: str, revert: bool = False) -> None:
@@ -198,7 +198,7 @@ class AMTManager:
self.amt_client.update_hit_review_status(HITId=amt_hit_id, Revert=revert)
except botocore.exceptions.ClientError as e:
- logging.warning(f"{amt_hit_id=}, {e}")
+ LOG.warning(f"{amt_hit_id=}, {e}")
error_msg = e.response["Error"]["Message"]
if "does not exist" in error_msg:
@@ -225,7 +225,7 @@ class AMTManager:
)
except botocore.exceptions.ClientError as e:
- logging.warning(f"{amt_worker_id=} {amt_assignment_id=}, {e}")
+ LOG.warning(f"{amt_worker_id=} {amt_assignment_id=}, {e}")
return None
def get_bonus(self, amt_assignment_id: str, payout_event_id: str) -> Bonus | None:
diff --git a/jb/managers/email_manager.py b/jb/managers/email_manager.py
index e740e20..78acc9d 100644
--- a/jb/managers/email_manager.py
+++ b/jb/managers/email_manager.py
@@ -1,9 +1,12 @@
import requests
+from generalresearch.config import is_debug
from jb.config import settings
MAUTIC_BASE_URL = "https://mail.jamesbillings67.com"
EMAIL_TEMPLATE_ID = 1
+
+assert settings.mautic_api_key
auth_headers = {"Authorization": f"Basic {settings.mautic_api_key.get_secret_value()}"}
@@ -22,6 +25,10 @@ def get_or_create_contact(email: str, amt_worker_id: str | None = None):
def send_login_email_from_url(mautic_url: str, magic_link: str) -> None:
+ if is_debug():
+ print("MAGIC_LINK: ", magic_link)
+ return
+
email_tokens = {
"magic_link": magic_link,
}
diff --git a/jb/managers/gr_api.py b/jb/managers/gr_api.py
index 494ceea..70c6a60 100644
--- a/jb/managers/gr_api.py
+++ b/jb/managers/gr_api.py
@@ -1,14 +1,12 @@
"""Client for General Research's product-user API."""
-import logging
from typing import Any
import requests
+from jb.decorators import LOG
from jb.models.auth import User
-logger = logging.getLogger(__name__)
-
class GRApiError(RuntimeError):
"""The General Research API could not satisfy a request."""
@@ -60,7 +58,7 @@ class GRApiManager:
f"General Research API request failed: {method} {url}"
) from exc
- def _parse_user_response(self, res: dict) -> User:
+ def _parse_user_response(self, res: dict[str, Any]) -> User:
return User.model_validate(
{
"product_user_id": res["product_user_id"],
@@ -98,7 +96,7 @@ class GRApiManager:
"""This should only be called once per user upon account creation.
A user cannot change their email address."""
url = f"{self.base_url}/{self.product_id}/user/{user.product_user_id}/metadata/"
- res = self._request(
+ _ = self._request(
"PATCH",
url,
json={"email_address": str(user.email)},
@@ -110,7 +108,7 @@ class GRApiManager:
if user.display_name is None:
return user
url = f"{self.base_url}/{self.product_id}/user/{user.product_user_id}/metadata/"
- res = self._request(
+ _ = self._request(
"PATCH",
url,
json={"display_name": user.display_name},
@@ -145,7 +143,7 @@ class GRApiManager:
raise
self.set_user_email(user)
transitioned_user = self.get_user(user.product_user_id)
- logger.warning(
+ LOG.warning(
"Transitioned product user from AMT worker %s to %s with email %s",
amt_worker_id,
transitioned_user.product_user_id,
diff --git a/jb/managers/hit.py b/jb/managers/hit.py
index a178d4d..2c6067b 100644
--- a/jb/managers/hit.py
+++ b/jb/managers/hit.py
@@ -306,7 +306,7 @@ class HitManager(PostgresManager):
def get_active_count(self, hit_type_id: int) -> int:
return self.pg_config.execute_sql_query(
- """
+ query="""
SELECT COUNT(1) as active_count
FROM mtwerk_hit
WHERE status = %(status)s