-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cleanup for alternate needle versions
There is now a minion task which will clean up alternate needle files created by the WebUI. The minimum retention time of the needle files can be set in the config, and defaults to 30 minutes
- Loading branch information
Showing
6 changed files
with
44 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright SUSE LLC | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
package OpenQA::Task::Needle::RemoveVersions; | ||
use Mojo::Base 'Mojolicious::Plugin', -signatures; | ||
|
||
use File::Find; | ||
use File::stat; | ||
|
||
my $minimum_retention_time; | ||
|
||
sub register ($self, $app, $job) { | ||
$minimum_retention_time = $app->config->{'scm git'}->{minimum_needle_retention_time} * 60 // 30 * 60; | ||
$app->minion->add_task(remove_needle_versions => sub ($job) { _remove_needle_versions($app, $job) }); | ||
} | ||
|
||
sub _remove_needle_versions ($app, $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); | ||
|
||
my $needle_versions_path = "/tmp/needle_dirs"; | ||
return unless -d $needle_versions_path; | ||
# Remove all temporary needles which haven't been accessed in time period specified in config | ||
find(\&wanted, $needle_versions_path); | ||
return; | ||
} | ||
|
||
sub wanted() { | ||
my $filepath = $File::Find::name; | ||
return unless -f $filepath; | ||
my $now = time; | ||
my $atime = stat($filepath)->atime; | ||
if (($now - $atime) > $minimum_retention_time) { | ||
unlink($filepath); | ||
} | ||
} | ||
|
||
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
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,2 @@ | ||
#!/bin/sh -e | ||
exec "$(dirname "$0")"/openqa eval -m production -V 'app->gru->enqueue(remove_needle_versions => [], {priority => 5, ttl => 172800, limit => 1})' "$@" |