diff options
| author | Max Nanis | 2026-02-19 20:11:41 -0500 |
|---|---|---|
| committer | Max Nanis | 2026-02-19 20:11:41 -0500 |
| commit | 8b31678c6e44400967d4934cd9f3c6c6ac0da721 (patch) | |
| tree | 41c5f4479c353a16da1a8b6fa9088abd084ea388 /jb/decorators.py | |
| parent | f0f96f83c2630e890a2cbcab53f77fd4c37e1684 (diff) | |
| download | amt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.tar.gz amt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.zip | |
Carer dir into project, some initial pytest, part of the flow tasks. License and Readme update
Diffstat (limited to 'jb/decorators.py')
| -rw-r--r-- | jb/decorators.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/jb/decorators.py b/jb/decorators.py new file mode 100644 index 0000000..54d36c7 --- /dev/null +++ b/jb/decorators.py @@ -0,0 +1,75 @@ +import boto3 +from botocore.config import Config +from generalresearchutils.pg_helper import PostgresConfig +from generalresearchutils.redis_helper import RedisConfig +from influxdb import InfluxDBClient +from mypy_boto3_mturk import MTurkClient +from mypy_boto3_sns import SNSClient + +from jb.config import settings +from jb.managers import Permission +from jb.managers.assignment import AssignmentManager +from jb.managers.bonus import BonusManager +from jb.managers.hit import HitTypeManager, HitManager, HitQuestionManager + +redis_config = RedisConfig( + dsn=settings.redis, + decode_responses=True, + socket_timeout=settings.redis_timeout, + socket_connect_timeout=settings.redis_timeout, +) +REDIS = redis_config.create_redis_client() + +CLIENT_CONFIG = Config( + # connect_timeout (float or int) – The time in seconds till a timeout + # exception is thrown when attempting to make a connection. The default + # is 60 seconds. + connect_timeout=1, + # read_timeout (float or int) – The time in seconds till a timeout + # exception is thrown when attempting to read from a connection. The + # default is 60 seconds. + read_timeout=2.5, +) + +# We shouldn't use this directly. Use our AMTManager wrapper +AMT_CLIENT: MTurkClient = boto3.client( + service_name="mturk", + region_name="us-east-1", + endpoint_url=str(settings.amt_endpoint), + aws_access_key_id=settings.amt_access_id, + aws_secret_access_key=settings.amt_secret_key, + config=CLIENT_CONFIG, +) + +SNS_CLIENT: SNSClient = boto3.client( + service_name="sns", + region_name="us-east-2", + aws_access_key_id=settings.amt_access_id, + aws_secret_access_key=settings.amt_secret_key, + config=CLIENT_CONFIG, +) + +pg_config = PostgresConfig( + dsn=settings.amt_jb_db, + connect_timeout=1, + statement_timeout=1, +) + +HTM = HitTypeManager( + pg_config=pg_config, permissions=[Permission.READ, Permission.CREATE] +) +HM = HitManager(pg_config=pg_config, permissions=[Permission.READ, Permission.CREATE]) +HQM = HitQuestionManager( + pg_config=pg_config, permissions=[Permission.READ, Permission.CREATE] +) +AM = AssignmentManager( + pg_config=pg_config, permissions=[Permission.READ, Permission.CREATE] +) + +BM = BonusManager( + pg_config=pg_config, permissions=[Permission.READ, Permission.CREATE] +) + +influx_client = None +if settings.influx_db: + influx_client = InfluxDBClient.from_dsn(str(settings.influx_db)) |
