diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-09-04 13:30:02 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2022-09-16 16:55:43 -0400 |
commit | 7983f052111d9551fc8341d71a15fb4b2ceaae8b (patch) | |
tree | 2c47df4988bcca5e8a48d897775104b904674503 | |
parent | 494fd3339819582668efd5a07b8bd3cd731e09b3 (diff) |
ci: Move stale job cleanup to get-test-job.c
It's more efficient to do it there, and now we emit a log message when
we delete a stale test job.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rwxr-xr-x | ci/get-test-job.sh | 17 | ||||
-rw-r--r-- | lib/get-test-job.c | 51 |
2 files changed, 41 insertions, 27 deletions
diff --git a/ci/get-test-job.sh b/ci/get-test-job.sh index bf64c6b..8347b08 100755 --- a/ci/get-test-job.sh +++ b/ci/get-test-job.sh @@ -2,24 +2,9 @@ [[ -f ~/.ktestrc ]] && . ~/.ktestrc -# Clean stale test jobs: - -cd $JOBSERVER_OUTPUT_DIR - -if [[ ! -f stale-job-cleanup ]]; then - touch stale-job-cleanup -fi - -if [[ $(find stale-job-cleanup -mmin +5) ]]; then - echo -n "Cleaning stale jobs.. " >&2 - find -size 0 -cmin +180 |xargs rm -f > /dev/null - touch stale-job-cleanup - echo " done" >&2 -fi - cd $JOBSERVER_HOME/linux flock --nonblock .git_fetch.lock git fetch --all > /dev/null make -C ~/ktest/lib get-test-job 1>&2 -~/ktest/lib/get-test-job -b ~/BRANCHES-TO-TEST -o $JOBSERVER_OUTPUT_DIR +~/ktest/lib/get-test-job -b ~/BRANCHES-TO-TEST -o $JOBSERVER_OUTPUT_DIR/c diff --git a/lib/get-test-job.c b/lib/get-test-job.c index f45b947..aab6a2f 100644 --- a/lib/get-test-job.c +++ b/lib/get-test-job.c @@ -10,6 +10,7 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> +#include <sys/time.h> #include <sys/types.h> #include <unistd.h> @@ -158,6 +159,31 @@ static char *slashes_to_dots(const char *str) return ret; } +static bool __lockfile_exists(const char *commitdir, + const char *testdir, + const char *lockfile, + bool create) +{ + if (!create) { + return access(lockfile, F_OK) == 0; + } else { + bool exists; + + if (mkdir(commitdir, 0755) < 0 && errno != EEXIST) + die("error creating %s", commitdir); + + if (mkdir(testdir, 0755) < 0 && errno != EEXIST) + die("error creating %s", testdir); + + int fd = open(lockfile, O_RDWR|O_CREAT|O_EXCL, 0644); + exists = fd < 0; + if (!exists) + close(fd); + + return exists; + } +} + static bool lockfile_exists(const char *commit, const char *test_path, const char *subtest, @@ -168,21 +194,24 @@ static bool lockfile_exists(const char *commit, char *commitdir = mprintf("%s/%s", outdir, commit); char *testdir = mprintf("%s/%s.%s", commitdir, test_name, subtest_mangled); char *lockfile = mprintf("%s/status", testdir); + struct timeval now; + struct stat statbuf; bool exists; - if (!create) { - exists = access(lockfile, F_OK) == 0; - } else { - if (mkdir(commitdir, 0755) < 0 && errno != EEXIST) - die("error creating %s", commitdir); + gettimeofday(&now, NULL); - if (mkdir(testdir, 0755) < 0 && errno != EEXIST) - die("error creating %s", testdir); + exists = __lockfile_exists(commitdir, testdir, lockfile, create); - int fd = open(lockfile, O_RDWR|O_CREAT|O_EXCL, 0644); - exists = fd < 0; - if (!exists) - close(fd); + if (exists && + !stat(lockfile, &statbuf) && + !statbuf.st_size && + S_ISREG(statbuf.st_mode) && + statbuf.st_ctime + 20 * 60 < now.tv_sec && + !unlink(lockfile)) { + fprintf(stderr, "Deleting stale test job %s %s %s (%lu minutes old)\n", + commit, test_name, subtest, + (now.tv_sec - statbuf.st_ctime) / 60); + exists = false; } free(lockfile); |