-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cleanup of temporary needle refs
* Use the settings key `temp_needle_refs_retention` which makes it clear that this setting is about temporary needle refs * Document settings key in default `openqa.ini` * Adapt the cleanup to be in accordance with the changed path for temporary needle refs * Rename cleanup task to `limit_temp_needle_refs` to be more in-line with existing cleanup tasks * Add systemd units to enqueue the cleanup task automatically * Change the default retention to two hours (from 30 minutes) * Use the modification time instead of the access time because the access time might be updated very to easily unintendedly * Use signal guard to retry cleanup in case the gru service is restarted * See https://progress.opensuse.org/issues/154783
- Loading branch information
Showing
12 changed files
with
98 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright SUSE LLC | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
package OpenQA::Task::Needle::LimitTempRefs; | ||
use Mojo::Base 'Mojolicious::Plugin', -signatures; | ||
|
||
use File::Find; | ||
use File::stat; | ||
use Fcntl qw(S_ISDIR); | ||
use OpenQA::Needles; | ||
use OpenQA::Task::SignalGuard; | ||
use Time::Seconds; | ||
|
||
my $retention; | ||
|
||
sub register ($self, $app, $job) { | ||
$retention = $app->config->{'scm git'}->{temp_needle_refs_retention} * ONE_MINUTE; | ||
$app->minion->add_task(limit_temp_needle_refs => sub ($job) { _limit($app, $job) }); | ||
} | ||
|
||
sub _limit ($app, $job) { | ||
my $ensure_task_retry_on_termination_signal_guard = OpenQA::Task::SignalGuard->new($job); | ||
|
||
return $job->finish({error => 'Another job to remove needle versions is running. Try again later.'}) | ||
unless my $guard = $app->minion->guard('limit_needle_versions_task', 7200); | ||
|
||
# remove all temporary needles which haven't been accessed in time period specified in config | ||
my $temp_dir = OpenQA::Needles::temp_dir; | ||
return undef unless -d $temp_dir; | ||
my $now = time; | ||
my $wanted = sub { | ||
return undef unless my $lstat = lstat $File::Find::name; | ||
return rmdir $File::Find::name if S_ISDIR($lstat->mode); # remove all empty dirs | ||
return unlink $File::Find::name if ($now - $lstat->mtime) > $retention; | ||
}; | ||
find({no_chdir => 1, bydepth => 1, wanted => $wanted}, $temp_dir); | ||
} | ||
|
||
1; |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...pt/openqa-enqueue-needle-versions-cleanup → script/openqa-enqueue-needle-ref-cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/sh -e | ||
exec "$(dirname "$0")"/openqa eval -m production -V 'app->gru->enqueue(remove_needle_versions => [], {priority => 5, ttl => 172800, limit => 1})' "$@" | ||
exec "$(dirname "$0")"/openqa eval -m production -V 'app->gru->enqueue(limit_temp_needle_refs => [], {priority => 5, ttl => 172800, limit => 1})' "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Enqueues a needle ref cleanup task for openQA. | ||
After=postgresql.service openqa-setup-db.service | ||
Wants=openqa-setup-db.service | ||
|
||
[Service] | ||
Type=oneshot | ||
User=geekotest | ||
ExecStart=/usr/share/openqa/script/openqa-enqueue-needle-ref-cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Enqueues a needle refs task for openQA every day. | ||
|
||
[Timer] | ||
OnCalendar=hourly | ||
Persistent=true | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters