synchronize non-train checkins from traewelling to travelynx

This commit is contained in:
Birte Kristina Friesel 2023-08-13 20:18:40 +02:00
parent 69edd81eeb
commit 293f0c7577
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA
2 changed files with 81 additions and 14 deletions

View file

@ -563,6 +563,11 @@ sub startup {
data => { trip_id => $journey->id } data => { trip_id => $journey->id }
); );
# mustn't be called during a transaction
if ( not $opt{in_transaction} ) {
$self->run_hook( $uid, 'checkin' );
}
$promise->resolve($journey); $promise->resolve($journey);
} }
)->catch( )->catch(
@ -953,6 +958,7 @@ sub startup {
my $now = DateTime->now( time_zone => 'Europe/Berlin' ); my $now = DateTime->now( time_zone => 'Europe/Berlin' );
my $journey = $self->in_transit->get( my $journey = $self->in_transit->get(
uid => $uid, uid => $uid,
db => $db,
with_data => 1, with_data => 1,
with_timestamps => 1, with_timestamps => 1,
with_visibility => 1, with_visibility => 1,
@ -1034,7 +1040,9 @@ sub startup {
); );
} }
if ($tx) {
$tx->commit; $tx->commit;
}
}; };
if ($@) { if ($@) {
@ -1932,19 +1940,76 @@ sub startup {
if ( $traewelling->{category} if ( $traewelling->{category}
!~ m{^ (?: national .* | regional .* | suburban ) $ }x ) !~ m{^ (?: national .* | regional .* | suburban ) $ }x )
{ {
$self->log->debug(
"... status is not a train, but $traewelling->{category}"); my $db = $self->pg->db;
my $tx = $db->begin;
$self->checkin_p(
station => $traewelling->{dep_eva},
train_id => $traewelling->{trip_id},
uid => $uid,
in_transaction => 1,
db => $db
)->then(
sub {
$self->log->debug("... handled origin");
return $self->checkout_p(
station => $traewelling->{arr_eva},
train_id => $traewelling->{trip_id},
uid => $uid,
in_transaction => 1,
db => $db
);
}
)->then(
sub {
my ( undef, $err ) = @_;
if ($err) {
$self->log->debug("... error: $err");
return Mojo::Promise->reject($err);
}
$self->log->debug("... handled destination");
if ( $traewelling->{message} ) {
$self->in_transit->update_user_data(
uid => $uid,
db => $db,
user_data =>
{ comment => $traewelling->{message} }
);
}
$self->traewelling->log( $self->traewelling->log(
uid => $uid, uid => $uid,
db => $db,
message => message =>
"$traewelling->{line} nach $traewelling->{arr_name} ist keine Zugfahrt (HAFAS-Kategorie '$traewelling->{category}')", "Eingecheckt in $traewelling->{line} nach $traewelling->{arr_name}",
status_id => $traewelling->{status_id}, status_id => $traewelling->{status_id},
); );
$self->traewelling->set_latest_pull_status_id( $self->traewelling->set_latest_pull_status_id(
uid => $uid, uid => $uid,
status_id => $traewelling->{status_id} status_id => $traewelling->{status_id},
db => $db
); );
return $promise->resolve;
$tx->commit;
$promise->resolve;
return;
}
)->catch(
sub {
my ($err) = @_;
$self->log->debug("... error: $err");
$self->traewelling->log(
uid => $uid,
message =>
"Konnte $traewelling->{line} nach $traewelling->{arr_name} nicht übernehmen: $err",
status_id => $traewelling->{status_id},
is_error => 1
);
$promise->resolve;
return;
}
)->wait;
return $promise;
} }
$self->iris->get_departures_p( $self->iris->get_departures_p(

View file

@ -116,6 +116,7 @@ sub get_status_p {
my $category = $status->{train}{category}; my $category = $status->{train}{category};
my $linename = $status->{train}{lineName}; my $linename = $status->{train}{lineName};
my $trip_id = $status->{train}{hafasId};
my ( $train_type, $train_line ) = split( qr{ }, $linename ); my ( $train_type, $train_line ) = split( qr{ }, $linename );
$promise->resolve( $promise->resolve(
{ {
@ -131,6 +132,7 @@ sub get_status_p {
arr_eva => $arr_eva, arr_eva => $arr_eva,
arr_ds100 => $arr_ds100, arr_ds100 => $arr_ds100,
arr_name => $arr_name, arr_name => $arr_name,
trip_id => $trip_id,
train_type => $train_type, train_type => $train_type,
line => $linename, line => $linename,
line_no => $train_line, line_no => $train_line,