Skip to content

Commit 8e95aea

Browse files
authored
feat: convert services to be used as instances (#44)
1 parent f55be6b commit 8e95aea

File tree

7 files changed

+879
-907
lines changed

7 files changed

+879
-907
lines changed

.github/workflows/lint-and-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434
with:
3535
path: ~/.cache
3636
key: self-runner-${{ runner.os }}-python-3.11-poetry-${{ hashFiles('poetry.lock') }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }}
37-
- name: Set up Python 3.11.0
37+
- name: Set up Python 3.11
3838
uses: actions/setup-python@v4
3939
with:
40-
python-version: 3.11.0-rc.2
40+
python-version: '3.11'
4141
- name: Install dependencies
4242
run: |
4343
cp env.sample .env

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ jobs:
3333
with:
3434
path: ~/.cache
3535
key: self-runner-${{ runner.os }}-python-3.11-poetry-${{ hashFiles('poetry.lock') }}-precommit-${{ hashFiles('.pre-commit-config.yaml') }}
36-
- name: Set up Python 3.11.0
36+
- name: Set up Python 3.11
3737
uses: actions/setup-python@v4
3838
with:
39-
python-version: 3.11.0-rc.2
39+
python-version: '3.11'
4040
- name: Install dependencies
4141
run: |
4242
cp env.sample .env

fastqueue/api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def not_found_exception_handler(request: Request, exc: NotFoundError):
7272

7373
@app.post("/topics", response_model=TopicSchema, status_code=status.HTTP_201_CREATED, tags=["topics"])
7474
def create_topic(data: CreateTopicSchema, session: Session = Depends(get_session)):
75-
return TopicService.create(data=data, session=session)
75+
return TopicService(session=session).create(data=data)
7676

7777

7878
@app.get(
@@ -83,7 +83,7 @@ def create_topic(data: CreateTopicSchema, session: Session = Depends(get_session
8383
responses={404: {"model": NotFoundSchema}},
8484
)
8585
def get_topic(topic_id: str, session: Session = Depends(get_session)):
86-
return TopicService.get(id=topic_id, session=session)
86+
return TopicService(session=session).get(id=topic_id)
8787

8888

8989
@app.delete(
@@ -93,17 +93,17 @@ def get_topic(topic_id: str, session: Session = Depends(get_session)):
9393
responses={404: {"model": NotFoundSchema}},
9494
)
9595
def delete_topic(topic_id: str, session: Session = Depends(get_session)):
96-
return TopicService.delete(id=topic_id, session=session)
96+
return TopicService(session=session).delete(id=topic_id)
9797

9898

9999
@app.get("/topics", response_model=ListTopicSchema, status_code=status.HTTP_200_OK, tags=["topics"])
100100
def list_topics(offset: int = 0, limit: int = 10, session: Session = Depends(get_session)):
101-
return TopicService.list(filters=None, offset=offset, limit=limit, session=session)
101+
return TopicService(session=session).list(filters=None, offset=offset, limit=limit)
102102

103103

104104
@app.post("/queues", response_model=QueueSchema, status_code=status.HTTP_201_CREATED, tags=["queues"])
105105
def create_queue(data: CreateQueueSchema, session: Session = Depends(get_session)):
106-
return QueueService.create(data=data, session=session)
106+
return QueueService(session=session).create(data=data)
107107

108108

109109
@app.get(
@@ -114,7 +114,7 @@ def create_queue(data: CreateQueueSchema, session: Session = Depends(get_session
114114
responses={404: {"model": NotFoundSchema}},
115115
)
116116
def get_queue(queue_id: str, session: Session = Depends(get_session)):
117-
return QueueService.get(id=queue_id, session=session)
117+
return QueueService(session=session).get(id=queue_id)
118118

119119

120120
@app.put(
@@ -125,7 +125,7 @@ def get_queue(queue_id: str, session: Session = Depends(get_session)):
125125
responses={404: {"model": NotFoundSchema}},
126126
)
127127
def update_queue(queue_id: str, data: UpdateQueueSchema, session: Session = Depends(get_session)):
128-
return QueueService.update(id=queue_id, data=data, session=session)
128+
return QueueService(session=session).update(id=queue_id, data=data)
129129

130130

131131
@app.get(
@@ -136,7 +136,7 @@ def update_queue(queue_id: str, data: UpdateQueueSchema, session: Session = Depe
136136
responses={404: {"model": NotFoundSchema}},
137137
)
138138
def get_queue_stats(queue_id: str, session: Session = Depends(get_session)):
139-
return QueueService.stats(id=queue_id, session=session)
139+
return QueueService(session=session).stats(id=queue_id)
140140

141141

142142
@app.put(
@@ -146,7 +146,7 @@ def get_queue_stats(queue_id: str, session: Session = Depends(get_session)):
146146
responses={404: {"model": NotFoundSchema}},
147147
)
148148
def purge_queue_messages(queue_id: str, session: Session = Depends(get_session)):
149-
return QueueService.purge(id=queue_id, session=session)
149+
return QueueService(session=session).purge(id=queue_id)
150150

151151

152152
@app.put(
@@ -156,7 +156,7 @@ def purge_queue_messages(queue_id: str, session: Session = Depends(get_session))
156156
responses={404: {"model": NotFoundSchema}},
157157
)
158158
def redrive_queue_messages(queue_id: str, data: RedriveQueueSchema, session: Session = Depends(get_session)):
159-
return QueueService.redrive(id=queue_id, data=data, session=session)
159+
return QueueService(session=session).redrive(id=queue_id, data=data)
160160

161161

162162
@app.delete(
@@ -166,12 +166,12 @@ def redrive_queue_messages(queue_id: str, data: RedriveQueueSchema, session: Ses
166166
responses={404: {"model": NotFoundSchema}},
167167
)
168168
def delete_queue(queue_id: str, session: Session = Depends(get_session)):
169-
return QueueService.delete(id=queue_id, session=session)
169+
return QueueService(session=session).delete(id=queue_id)
170170

171171

172172
@app.get("/queues", response_model=ListQueueSchema, status_code=status.HTTP_200_OK, tags=["queues"])
173173
def list_queues(offset: int = 0, limit: int = 10, session: Session = Depends(get_session)):
174-
return QueueService.list(filters=None, offset=offset, limit=limit, session=session)
174+
return QueueService(session=session).list(filters=None, offset=offset, limit=limit)
175175

176176

177177
@app.post(
@@ -182,7 +182,7 @@ def list_queues(offset: int = 0, limit: int = 10, session: Session = Depends(get
182182
responses={404: {"model": NotFoundSchema}},
183183
)
184184
def create_message(topic_id: str, data: CreateMessageSchema, session: Session = Depends(get_session)):
185-
return MessageService.create(topic_id=topic_id, data=data, session=session)
185+
return MessageService(session=session).create(topic_id=topic_id, data=data)
186186

187187

188188
@app.get(
@@ -193,17 +193,17 @@ def create_message(topic_id: str, data: CreateMessageSchema, session: Session =
193193
responses={404: {"model": NotFoundSchema}},
194194
)
195195
def list_messages_for_consume(queue_id: str, limit: int = 10, session: Session = Depends(get_session)):
196-
return MessageService.list_for_consume(queue_id=queue_id, limit=limit, session=session)
196+
return MessageService(session=session).list_for_consume(queue_id=queue_id, limit=limit)
197197

198198

199199
@app.put("/messages/{message_id}/ack", status_code=status.HTTP_204_NO_CONTENT, tags=["messages"])
200200
def ack_message(message_id: str, session: Session = Depends(get_session)):
201-
return MessageService.ack(id=message_id, session=session)
201+
return MessageService(session=session).ack(id=message_id)
202202

203203

204204
@app.put("/messages/{message_id}/nack", status_code=status.HTTP_204_NO_CONTENT, tags=["messages"])
205205
def nack_message(message_id: str, session: Session = Depends(get_session)):
206-
return MessageService.nack(id=message_id, session=session)
206+
return MessageService(session=session).nack(id=message_id)
207207

208208

209209
def run_server():

0 commit comments

Comments
 (0)