fix: attempt to avoid database timeouts due to locking

This commit is contained in:
Kwonunn 2024-10-17 11:48:22 +02:00
parent 2db3b373bb
commit 3875197a1b
2 changed files with 21 additions and 13 deletions

View file

@ -6,7 +6,8 @@ jobs:
runs-on: docker runs-on: docker
container: container:
image: code.forgejo.org/oci/debian:bookworm image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example:/srv/example" volumes:
- /srv/example:/srv/example
steps: steps:
- run: | - run: |
while ! [ -f /srv/example/schedule-noncancel/PUSHED ]; do while ! [ -f /srv/example/schedule-noncancel/PUSHED ]; do

View file

@ -12,20 +12,20 @@ fi
# #
forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token
# Prevent test failure because the db is occupied
sqlite3 $DIR/forgejo-work-path/forgejo.db "pragma busy_timeout=20000"
# #
# get the run id of the workflow that just started # get the run id of the workflow that just started
# #
getScheduleRun() { getScheduleRun() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \ rm -f $DIR/forgejo-work-path/forgejo.copy.db
"select action_run.id \ cp $DIR/forgejo-work-path/forgejo.db $DIR/forgejo-work-path/forgejo.copy.db
sqlite3 $DIR/forgejo-work-path/forgejo.copy.db \
"pragma busy_timeout = 5000; \
select action_run.id \
from action_run \ from action_run \
inner join action_schedule on action_run.schedule_id = action_schedule.id \ inner join action_schedule on action_run.schedule_id = action_schedule.id \
inner join repository on action_schedule.repo_id = repository.id \ inner join repository on action_schedule.repo_id = repository.id \
where repository.name = 'example-schedule-noncancel' \ where repository.name = 'example-schedule-noncancel' \
order by action_run.created desc limit 1" order by action_run.created desc limit 1" | sed '2q;d'
} }
run_id=$(getScheduleRun) run_id=$(getScheduleRun)
@ -41,11 +41,14 @@ echo Schedule run id: $run_id
# Wait for it to be started # Wait for it to be started
# #
checkStarted() { checkStarted() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \ rm -f $DIR/forgejo-work-path/forgejo.copy.db
"select id \ cp $DIR/forgejo-work-path/forgejo.db $DIR/forgejo-work-path/forgejo.copy.db
sqlite3 $DIR/forgejo-work-path/forgejo.copy.db \
"pragma busy_timeout = 5000; \
select id \
from action_run \ from action_run \
where id = $run_id \ where id = $run_id \
and started is not null" and started is not null" | sed '2q;d'
} }
started_check=$(checkStarted) started_check=$(checkStarted)
@ -73,11 +76,14 @@ touch /srv/example/schedule-noncancel/PUSHED
echo Wait for workflow to finish echo Wait for workflow to finish
checkFinished() { checkFinished() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \ rm -f $DIR/forgejo-work-path/forgejo.copy.db
"select status \ cp $DIR/forgejo-work-path/forgejo.db $DIR/forgejo-work-path/forgejo.copy.db
sqlite3 $DIR/forgejo-work-path/forgejo.copy.db \
"pragma busy_timeout = 5000; \
select status \
from action_run \ from action_run \
where id = $run_id \ where id = $run_id \
and (status != 6 and status != 5)" and (status != 6 and status != 5)" | sed '2q;d'
} }
finished_status=$(checkFinished) finished_status=$(checkFinished)
@ -88,5 +94,6 @@ while [ -z $finished_status ]; do
done done
echo Workflow finished. echo Workflow finished.
rm -f $DIR/forgejo-work-path/forgejo.copy.db
test $finished_status = 1 test $finished_status = 1