Skip to content

Commit

Permalink
backstage: properly close DB connections in minion jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-suse committed Nov 27, 2024
1 parent d32172e commit 16e9830
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ setup_system_user:
setup_system_db:
sudo -u postgres createuser mirrorcache
sudo -u postgres createdb mirrorcache
sudo -u postgres psql -c 'GRANT all ON SCHEMA public TO mirrorcache' mirrorcache

setup_production_assets:
cd "${DESTDIR}"/usr/share/mirrorcache/ && \
Expand Down
17 changes: 17 additions & 0 deletions lib/MirrorCache/WebAPI/Command/backstage/run.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ sub run {
$self->app->log->info('Resetting all leftover locks after restart');
$minion->reset({locks => 1});
}
$minion->on(
worker => sub () {
my (undef, $worker) = @_;
$worker->on(
dequeue => sub () {
my (undef, $job) = @_;
$job->on(
cleanup => sub () {
my ($j) = @_;
$j->app->minion->backend->mysql->close_idle_connections() unless $j->app->schema->pg;
$j->app->schema->disconnect_db;
}
);
}
);
}
);
$self->SUPER::run(@args);
}

Expand Down

0 comments on commit 16e9830

Please sign in to comment.