Skip to content

Commit

Permalink
use 'maintenance' file to stop background jobs when running DB upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
derf committed Jun 12, 2024
1 parent 0b725cb commit 2d72ff8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Travelynx/Command/traewelling.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ sub pull_sync {
my $request_count = 0;
for my $account_data ( $self->app->traewelling->get_pull_accounts ) {

if ( -e 'maintenance' ) {
return;
}

my $in_transit = $self->app->in_transit->get(
uid => $account_data->{user_id},
);
Expand Down Expand Up @@ -84,6 +88,11 @@ sub push_sync {
my %push_result;

for my $candidate ( $self->app->traewelling->get_pushable_accounts ) {

if ( -e 'maintenance' ) {
return;
}

$self->app->log->debug(
"Pushing to Traewelling for UID $candidate->{uid}");
my $trip_id = $candidate->{journey_data}{trip_id};
Expand Down Expand Up @@ -140,6 +149,10 @@ sub run {

my $trwl_pull_finished_at = DateTime->now( time_zone => 'Europe/Berlin' );

if ( -e 'maintenance' ) {
return;
}

my $trwl_push_duration = $trwl_push_finished_at->epoch - $started_at->epoch;
my $trwl_pull_duration
= $trwl_pull_finished_at->epoch - $trwl_push_finished_at->epoch;
Expand Down
4 changes: 4 additions & 0 deletions lib/Travelynx/Command/work.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ sub run {

for my $entry ( $self->app->in_transit->get_all_active ) {

if ( -e 'maintenance' ) {
return;
}

my $uid = $entry->{user_id};
my $dep = $entry->{dep_eva};
my $arr = $entry->{arr_eva};
Expand Down
2 changes: 2 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ if [ "$1" = "with-deps" ]; then
carton install
cd ..
sudo systemctl stop travelynx
touch maintenance
mv local local.old
mv local.new/local .
perl index.pl database migrate
rm -f maintenance
sudo systemctl start travelynx
elif perl index.pl database has-current-schema; then
sudo systemctl reload travelynx
Expand Down

0 comments on commit 2d72ff8

Please sign in to comment.