Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions gorgone/gorgone/modules/core/dbcleaner/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ sub new {
bless $connector, $class;

$connector->{purge_timer} = time();
$connector->{purge_vacuum_timer} = time();


$connector->set_signal_handlers();
return $connector;
Expand Down Expand Up @@ -100,7 +102,44 @@ sub exit_process {
$self->{logger}->writeLogInfo("[dbcleaner] $$ has quit");
exit(0);
}
# apply vacuum on the database every week
sub action_dbvacuum {
my ($self, %options) = @_;

$options{token} = $self->generate_token() if (!defined($options{token}));

if (defined($options{cycle})) {
return 0 if ((time() - $self->{purge_vacuum_timer}) < 3600*24*7); # doing vacuum every week as it can be slow on some database
}
$self->{logger}->writeLogDebug("[dbcleaner] vacuum database in progress...");
my ($status) = $self->{db_gorgone}->query({
query => "VACUUM"
});
$self->{purge_vacuum_timer} = time();

$self->{logger}->writeLogDebug("[dbcleaner] vacuum finished");

if ($status == -1) {
$self->send_log(
code => GORGONE_ACTION_FINISH_KO,
token => $options{token},
data => {
message => 'action db vacuum failed'
}
);
return 0;
}

$self->send_log(
code => GORGONE_ACTION_FINISH_OK,
token => $options{token},
data => {
message => 'action db vacuum finished'
}
);
return 0;
}
# purge database
sub action_dbclean {
my ($self, %options) = @_;

Expand All @@ -127,6 +166,7 @@ sub action_dbclean {
query => "DELETE FROM gorgone_history WHERE (instant = 1 AND `ctime` < " . (time() - 86400) . ") OR `ctime` < ?",
bind_values => [time() - $self->{config}->{purge_history_time}]
});

$self->{purge_timer} = time();

$self->{logger}->writeLogDebug("[dbcleaner] Purge finished");
Expand Down Expand Up @@ -158,6 +198,8 @@ sub periodic_exec {
}

$connector->action_dbclean(cycle => 1);
$connector->action_dbvacuum(cycle => 1);

}

sub run {
Expand Down
Loading