Skip to content

Commit 2f18c6d

Browse files
authored
fixed installation flow (#152)
PHP_CLI_SERVER_WORKERS=2 to `php -S` This should prevent timeouts during the installation flow in dev environment without apache/nginx. --------- Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
1 parent ae0ae0a commit 2f18c6d

File tree

5 files changed

+54
-43
lines changed

5 files changed

+54
-43
lines changed

.github/workflows/analysis-coverage.yml

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
--admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }}
100100
php occ config:system:set loglevel --value=1 --type=integer
101101
php occ config:system:set debug --value=true --type=boolean
102-
php -S localhost:8080 &
102+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
103103
104104
- name: Checkout NcPyApi
105105
uses: actions/checkout@v4
@@ -143,7 +143,7 @@ jobs:
143143
- name: Enable Talk
144144
run: php occ app:enable spreed
145145

146-
- name: Generate coverage report
146+
- name: Generate coverage report (1)
147147
working-directory: nc_py_api
148148
run: |
149149
coverage run --data-file=.coverage.talk_bot tests/_talk_bot.py &
@@ -152,6 +152,23 @@ jobs:
152152
kill -15 $(cat /tmp/_talk_bot.pid)
153153
timeout 3m tail --pid=$(cat /tmp/_talk_bot.pid) -f /dev/null
154154
coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py
155+
156+
- name: Uninstall NcPyApi
157+
run: |
158+
php occ app_api:app:unregister "$APP_ID" --silent
159+
php occ app_api:daemon:unregister manual_install
160+
161+
- name: Generate coverage report (2)
162+
working-directory: nc_py_api
163+
run: |
164+
coverage run --data-file=.coverage.ci_install_models tests/_install_init_handler_models.py &
165+
echo $! > /tmp/_install_models.pid
166+
python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5
167+
cd ..
168+
sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT"
169+
kill -15 $(cat /tmp/_install_models.pid)
170+
timeout 3m tail --pid=$(cat /tmp/_install_models.pid) -f /dev/null
171+
cd nc_py_api
155172
coverage combine && coverage xml && coverage html
156173
157174
- name: HTML coverage to artifacts
@@ -243,7 +260,7 @@ jobs:
243260
--admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }}
244261
php occ config:system:set loglevel --value=1
245262
php occ config:system:set debug --value=true --type=boolean
246-
php -S localhost:8080 &
263+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
247264
248265
- name: Checkout NcPyApi
249266
uses: actions/checkout@v4
@@ -287,7 +304,7 @@ jobs:
287304
- name: Enable Talk
288305
run: php occ app:enable spreed
289306

290-
- name: Generate coverage report
307+
- name: Generate coverage report (1)
291308
working-directory: nc_py_api
292309
run: |
293310
coverage run --data-file=.coverage.talk_bot tests/_talk_bot.py &
@@ -296,6 +313,23 @@ jobs:
296313
kill -15 $(cat /tmp/_talk_bot.pid)
297314
timeout 3m tail --pid=$(cat /tmp/_talk_bot.pid) -f /dev/null
298315
coverage run --data-file=.coverage.at_the_end -m pytest tests/_tests_at_the_end.py
316+
317+
- name: Uninstall NcPyApi
318+
run: |
319+
php occ app_api:app:unregister "$APP_ID" --silent
320+
php occ app_api:daemon:unregister manual_install
321+
322+
- name: Generate coverage report (2)
323+
working-directory: nc_py_api
324+
run: |
325+
coverage run --data-file=.coverage.ci_install_models tests/_install_init_handler_models.py &
326+
echo $! > /tmp/_install_models.pid
327+
python3 tests/_install_wait.py http://127.0.0.1:$APP_PORT/heartbeat "\"status\":\"ok\"" 15 0.5
328+
cd ..
329+
sh nc_py_api/scripts/ci_register.sh "$APP_ID" "$APP_VERSION" "$APP_SECRET" "localhost" "$APP_PORT"
330+
kill -15 $(cat /tmp/_install_models.pid)
331+
timeout 3m tail --pid=$(cat /tmp/_install_models.pid) -f /dev/null
332+
cd nc_py_api
299333
coverage combine && coverage xml && coverage html
300334
301335
- name: HTML coverage to artifacts
@@ -381,7 +415,7 @@ jobs:
381415
--admin-user admin --admin-pass ${{ env.NC_AUTH_PASS }}
382416
php occ config:system:set loglevel --value=1 --type=integer
383417
php occ config:system:set debug --value=true --type=boolean
384-
php -S localhost:8080 &
418+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
385419
386420
- name: Checkout NcPyApi
387421
uses: actions/checkout@v4
@@ -512,7 +546,7 @@ jobs:
512546
./occ config:system:set debug --value=true --type=boolean
513547
./occ app:enable notifications
514548
./occ app:enable notes
515-
php -S localhost:8080 &
549+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
516550
517551
- name: Checkout NcPyApi
518552
uses: actions/checkout@v4
@@ -662,7 +696,7 @@ jobs:
662696
./occ config:system:set debug --value=true --type=boolean
663697
./occ app:enable notifications
664698
./occ app:enable activity
665-
php -S localhost:8080 &
699+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
666700
667701
- name: Checkout NcPyApi
668702
uses: actions/checkout@v4
@@ -802,7 +836,7 @@ jobs:
802836
./occ config:system:set debug --value=true --type=boolean
803837
./occ app:enable activity
804838
./occ app:enable notes
805-
php -S localhost:8080 &
839+
PHP_CLI_SERVER_WORKERS=2 php -S localhost:8080 &
806840
807841
- name: Checkout NcPyApi
808842
uses: actions/checkout@v4
@@ -847,7 +881,7 @@ jobs:
847881
uses: codecov/codecov-action@v3
848882
with:
849883
token: ${{ secrets.CODECOV_TOKEN }}
850-
name: coverage_sqlite_${{ matrix.nextcloud }}
884+
name: coverage_sqlite_${{ matrix.nextcloud }}_client
851885
file: coverage.xml
852886
fail_ci_if_error: true
853887
verbose: true

nc_py_api/ex_app/integration_fastapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def set_handlers(
7575
:param models_download_params: Parameters to pass to ``snapshot_download`` function from **huggingface_hub**.
7676
"""
7777

78-
def fetch_models_task(models: dict):
78+
def fetch_models_task(models: list[str]) -> None:
7979
if models:
8080
from huggingface_hub import snapshot_download # noqa isort:skip pylint: disable=C0415 disable=E0401
8181
from tqdm import tqdm # noqa isort:skip pylint: disable=C0415 disable=E0401
@@ -115,5 +115,5 @@ def heartbeat_callback():
115115

116116
@fast_api_app.post("/init")
117117
def init_callback(background_tasks: BackgroundTasks):
118-
background_tasks.add_task(fetch_models_task, models_to_fetch if models_to_fetch else {})
118+
background_tasks.add_task(fetch_models_task, models_to_fetch if models_to_fetch else [])
119119
return responses.JSONResponse(content={}, status_code=200)

tests/_install.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ def enabled_handler(enabled: bool, nc: NextcloudApp) -> str:
2727
return ""
2828

2929

30+
def init_handler():
31+
NextcloudApp().set_init_status(100)
32+
33+
3034
def heartbeat_callback():
3135
return "ok"
3236

3337

3438
@APP.on_event("startup")
3539
def initialization():
36-
ex_app.set_handlers(APP, enabled_handler, heartbeat_callback)
40+
ex_app.set_handlers(APP, enabled_handler, heartbeat_callback, init_handler=init_handler)
3741

3842

3943
if __name__ == "__main__":

tests/_install_init_handler_models.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@
77
MODEL_NAME = "MBZUAI/LaMini-T5-61M"
88

99

10-
def enabled_handler(_enabled: bool, _nc: NextcloudApp) -> str:
11-
if _enabled:
10+
def enabled_handler(enabled: bool, _nc: NextcloudApp) -> str:
11+
if enabled:
1212
try:
13-
snapshot_download(MODEL_NAME, local_files_only=True)
13+
snapshot_download(MODEL_NAME, local_files_only=True, cache_dir=ex_app.persistent_storage())
1414
except Exception: # noqa
1515
return "model not found"
1616
return ""
1717

1818

19-
def init_handler():
20-
NextcloudApp().set_init_status(100)
21-
22-
2319
@APP.on_event("startup")
2420
def initialization():
25-
ex_app.set_handlers(APP, enabled_handler, init_handler=init_handler, models_to_fetch=[MODEL_NAME])
21+
ex_app.set_handlers(APP, enabled_handler, models_to_fetch=[MODEL_NAME])
2622

2723

2824
if __name__ == "__main__":

tests/_tests_at_the_end.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,3 @@ def test_ex_app_enable_disable(nc_client, nc_app):
2828
assert nc_client.apps.ex_app_is_enabled("nc_py_api") is True
2929
finally:
3030
r.terminate()
31-
32-
33-
def test_install_init_handler_models(nc_client, nc_app):
34-
child_environment = os.environ.copy()
35-
child_environment["APP_PORT"] = os.environ.get("APP_PORT", "9009")
36-
r = Popen(
37-
[
38-
sys.executable,
39-
os.path.join(os.path.dirname(os.path.abspath(__file__)), "_install_init_handler_models.py"),
40-
],
41-
env=child_environment,
42-
cwd=os.getcwd(),
43-
)
44-
url = f"http://127.0.0.1:{child_environment['APP_PORT']}/heartbeat"
45-
try:
46-
if check_heartbeat(url, '"status":"ok"', 15, 0.3):
47-
raise RuntimeError("`_install_init_handler_models` can not start.")
48-
if nc_client.apps.ex_app_is_enabled("nc_py_api"):
49-
nc_client.apps.ex_app_disable("nc_py_api")
50-
nc_client.apps.ex_app_enable("nc_py_api")
51-
assert nc_client.apps.ex_app_is_enabled("nc_py_api") is True
52-
finally:
53-
r.terminate()

0 commit comments

Comments
 (0)