-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_extensions.py
More file actions
80 lines (64 loc) · 2.12 KB
/
add_extensions.py
File metadata and controls
80 lines (64 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
from typing import Optional, Dict
from walrus import * # noqa: F403
from dotenv import load_dotenv
from flask_sqlalchemy import SQLAlchemy
from passlib.context import CryptContext
from huey import (
RedisExpireHuey, RedisHuey,
FileHuey, MemoryHuey, SqliteHuey,
PriorityRedisExpireHuey, PriorityRedisHuey
)
load_dotenv()
class HueyTemplate:
_types = {
'default': RedisHuey,
'redis': RedisHuey,
'file': FileHuey,
'mem': MemoryHuey,
'priorityh': PriorityRedisHuey,
'priorityhex': PriorityRedisExpireHuey,
'redisex': RedisExpireHuey
}
def __init__(self, config=None, type_name: Optional[str] = None):
if config:
if type_name:
self.huey = HueyTemplate._types[type_name](**config)
else:
self.huey = HueyTemplate._types['default'](**config)
self.db = SQLAlchemy()
def get_flask_app(self, config: Optional[Dict] = None):
from flask import Flask
app = Flask("huey_app")
if config:
app.config.from_object(config)
self.db.init_app(app)
return app
class RedCache:
# class RedisDBEnum(enum.Enum):
# HUEY_STORE = 0
# DATA_STORE = 1
# CATEGORY_GEO_STORE = 2
def __init__(self, db=1):
self.client = Walrus( # noqa: F405
os.getenv('REDIS_HOST', '127.0.0.1'),
os.getenv('REDIS_PORT', 6378),
decode_responses=True,
password=os.getenv('REDIS_PASS'),
db=db
)
def force_delete(self):
pass
# def exists(self, id):
# return self.client.exists(id)
# def delete(self, id):
# return self.client.delete(id)
# def get(self, id):
# return self.client.get(id)
pwd_context = CryptContext(schemes=["argon2", "bcrypt"], deprecated="auto")
data_store = redis_ = RedCache().client
customer_pos_store = redis_2 = RedCache(2).client
socket_id_store = redis_4 = RedCache(4).client
cat_geo_store = redis_5 = RedCache(5).client
artisan_cat_geo_store = redis_6 = RedCache(6).client
unmatched_bookings = redis_7 = RedCache(7).client