Skip to content

Commit 87c844e

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/servc
2 parents fbf9a08 + a1c1873 commit 87c844e

7 files changed

Lines changed: 94 additions & 9 deletions

File tree

.github/workflows/servc.yml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,73 @@ jobs:
66
servc:
77
runs-on: ubuntu-latest
88

9+
strategy:
10+
matrix:
11+
python-version:
12+
- 3.13
13+
14+
services:
15+
rabbitmq:
16+
image: rabbitmq:3
17+
env:
18+
RABBITMQ_DEFAULT_USER: guest
19+
RABBITMQ_DEFAULT_PASS: guest
20+
ports:
21+
- 5672/tcp
22+
23+
redis:
24+
image: redis
25+
options: >-
26+
--health-cmd "redis-cli ping"
27+
--health-interval 10s
28+
--health-timeout 5s
29+
--health-retries 5
30+
ports:
31+
- 6379/tcp
32+
933
steps:
10-
- name: Run Servc Tests
11-
uses: serv-c/docs@0.2.12
34+
- if: github.server_url != 'https://github.com'
35+
run: sleep 20s
36+
37+
- name: Checkout Code
38+
uses: actions/checkout@v4
39+
with:
40+
submodules: true
41+
42+
- name: Setup Python ${{ matrix.python-version }}
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: ${{ matrix.python-version }}
46+
47+
- name: Install dependencies
48+
run: pip install -r requirements.txt
49+
50+
- name: Set Environment Variables
51+
run: |
52+
echo "CURRENT_PATH=$(pwd)" >> $GITHUB_ENV
53+
chmod +x start.sh
54+
55+
- name: Checkout Serv-C
56+
uses: actions/checkout@v4
57+
with:
58+
repository: serv-c/docs
59+
ref: main
60+
path: servc-docs
61+
sparse-checkout: |
62+
tests
63+
requirements.test.txt
64+
config/.placeholder
65+
66+
- name: Install Serv-C Dependencies
67+
run: pip install -r requirements.test.txt
68+
shell: bash
69+
working-directory: servc-docs
70+
71+
- name: Run Serv-C tests
72+
shell: bash
73+
working-directory: servc-docs
74+
env:
75+
START_SCRIPT: ${{ env.CURRENT_PATH }}/start.sh
76+
CACHE_URL: redis://redis
77+
BUS_URL: amqp://guest:guest@rabbitmq
78+
run: python -m unittest tests/**/*.py

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Type check
4545
run: |
4646
pip install mypy
47-
pip install types-PyYAML types-simplejson
47+
pip install types-PyYAML types-simplejson types-redis
4848
mypy servc
4949
5050
- name: Install dependencies

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-i https://pypi.org/simple
22
pika==1.3.2
3-
redis==5.0.1
3+
redis==5.2.0
44
simplejson==3.19.2
55
flask==3.0.1
66
pyyaml==6.0.2

servc/svc/com/http/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from multiprocessing import Process
33
from typing import Dict, Tuple, TypedDict
44

5-
from flask import Flask, jsonify, request
5+
from flask import Flask, jsonify, request # type: ignore
66

77
from servc.svc import ComponentType, Middleware
88
from servc.svc.client.send import sendMessage

servc/svc/com/worker/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class WorkerComponent(Middleware):
4444

4545
_config: Config
4646

47+
_bindToEventExchange: bool
48+
4749
def __init__(
4850
self,
4951
route: str,
@@ -65,6 +67,11 @@ def __init__(
6567
self._bus = bus
6668
self._cache = cache
6769
self._config = config
70+
self._bindToEventExchange = (
71+
config.get("conf.bus.bindtoeventexchange")
72+
if len(self._eventResolvers.keys()) > 0
73+
else False
74+
)
6875

6976
self._resolvers["healthz"] = lambda *args: HEALTHZ(*args)
7077

@@ -84,10 +91,18 @@ def _close(self):
8491
def connect(self):
8592
super().connect()
8693

94+
print("Consumer now Subscribing", flush=True)
95+
print(" Route:", self._route, flush=True)
96+
print(" InstanceId:", self._instanceId, flush=True)
97+
print(" Resolvers:", self._resolvers.keys(), flush=True)
98+
print(" Event Resolvers:", self._eventResolvers.keys(), flush=True)
99+
print(" Bind to Event Exchange:", self._bindToEventExchange, flush=True)
100+
87101
self._bus.subscribe(
88102
self._route,
89103
self.inputProcessor,
90104
self._onConsuming,
105+
bindEventExchange=self._bindToEventExchange,
91106
)
92107

93108
def emitEvent(self, eventName: str, details: Any):
@@ -173,14 +188,12 @@ def inputProcessor(self, message: Any) -> StatusCode:
173188
artifact["inputs"],
174189
self._children,
175190
)
176-
cache.setKey(message["id"], getAnswerArtifact(
177-
message["id"], response))
191+
cache.setKey(message["id"], getAnswerArtifact(message["id"], response))
178192
return StatusCode.OK
179193
except Exception as e:
180194
cache.setKey(
181195
message["id"],
182-
getErrorArtifact(message["id"], str(
183-
e), StatusCode.SERVER_ERROR),
196+
getErrorArtifact(message["id"], str(e), StatusCode.SERVER_ERROR),
184197
)
185198
return StatusCode.SERVER_ERROR
186199

servc/svc/config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
os.getenv("CONF__BUS__ROUTEMAP", json.dumps({}))
2020
),
2121
"conf.bus.prefix": "",
22+
"conf.bus.bindtoeventexchange": True,
2223
}
2324

2425

start.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
folder=$(dirname $START_SCRIPT)
4+
python $folder/main.py

0 commit comments

Comments
 (0)