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
container:
image: code.forgejo.org/oci/debian:bookworm
options: "--volume /srv/example:/srv/example"
volumes:
- /srv/example:/srv/example
steps:
- run: |
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
# 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
#
getScheduleRun() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \
"select action_run.id \
rm -f $DIR/forgejo-work-path/forgejo.copy.db
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 \
inner join action_schedule on action_run.schedule_id = action_schedule.id \
inner join repository on action_schedule.repo_id = repository.id \
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)
@ -41,11 +41,14 @@ echo Schedule run id: $run_id
# Wait for it to be started
#
checkStarted() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \
"select id \
rm -f $DIR/forgejo-work-path/forgejo.copy.db
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 \
where id = $run_id \
and started is not null"
and started is not null" | sed '2q;d'
}
started_check=$(checkStarted)
@ -73,11 +76,14 @@ touch /srv/example/schedule-noncancel/PUSHED
echo Wait for workflow to finish
checkFinished() {
sqlite3 $DIR/forgejo-work-path/forgejo.db \
"select status \
rm -f $DIR/forgejo-work-path/forgejo.copy.db
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 \
where id = $run_id \
and (status != 6 and status != 5)"
and (status != 6 and status != 5)" | sed '2q;d'
}
finished_status=$(checkFinished)
@ -88,5 +94,6 @@ while [ -z $finished_status ]; do
done
echo Workflow finished.
rm -f $DIR/forgejo-work-path/forgejo.copy.db
test $finished_status = 1