work: guard HAFAS updates via eval as well

This commit is contained in:
Birte Kristina Friesel 2024-08-16 16:52:14 +02:00
parent 170aa150b1
commit f0b70c4dab
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA

View file

@ -49,109 +49,119 @@ sub run {
if ( $entry->{is_hafas} ) { if ( $entry->{is_hafas} ) {
$self->app->hafas->get_journey_p( eval {
trip_id => $train_id,
service => $entry->{backend_name}
)->then(
sub {
my ($journey) = @_;
my $found_dep; $self->app->hafas->get_journey_p(
my $found_arr; trip_id => $train_id,
for my $stop ( $journey->route ) { service => $entry->{backend_name}
if ( $stop->loc->eva == $dep ) { )->then(
$found_dep = $stop; sub {
} my ($journey) = @_;
if ( $arr and $stop->loc->eva == $arr ) {
$found_arr = $stop;
last;
}
}
if ( not $found_dep ) {
$self->app->log->debug(
"Did not find $dep within journey $train_id");
return;
}
if ( $found_dep->rt_dep ) { my $found_dep;
$self->app->in_transit->update_departure_hafas( my $found_arr;
uid => $uid, for my $stop ( $journey->route ) {
journey => $journey, if ( $stop->loc->eva == $dep ) {
stop => $found_dep, $found_dep = $stop;
dep_eva => $dep, }
arr_eva => $arr if ( $arr and $stop->loc->eva == $arr ) {
); $found_arr = $stop;
if ( $entry->{backend_id} <= 1 last;
and $journey->class <= 16 }
and $found_dep->rt_dep->epoch > $now->epoch ) }
{ if ( not $found_dep ) {
$self->app->add_wagonorder( $self->app->log->debug(
uid => $uid, "Did not find $dep within journey $train_id");
train_id => $journey->id, return;
is_departure => 1, }
eva => $dep,
datetime => $found_dep->sched_dep, if ( $found_dep->rt_dep ) {
train_type => $journey->type, $self->app->in_transit->update_departure_hafas(
train_no => $journey->number, uid => $uid,
journey => $journey,
stop => $found_dep,
dep_eva => $dep,
arr_eva => $arr
); );
$self->app->add_stationinfo( $uid, 1, $journey->id, if ( $entry->{backend_id} <= 1
$found_dep->loc->eva ); and $journey->class <= 16
and $found_dep->rt_dep->epoch > $now->epoch )
{
$self->app->add_wagonorder(
uid => $uid,
train_id => $journey->id,
is_departure => 1,
eva => $dep,
datetime => $found_dep->sched_dep,
train_type => $journey->type,
train_no => $journey->number,
);
$self->app->add_stationinfo( $uid, 1,
$journey->id, $found_dep->loc->eva );
}
} }
}
if ( $found_arr and $found_arr->rt_arr ) { if ( $found_arr and $found_arr->rt_arr ) {
$self->app->in_transit->update_arrival_hafas( $self->app->in_transit->update_arrival_hafas(
uid => $uid, uid => $uid,
journey => $journey, journey => $journey,
stop => $found_arr, stop => $found_arr,
dep_eva => $dep, dep_eva => $dep,
arr_eva => $arr arr_eva => $arr
);
if ( $entry->{backend_id} <= 1
and $journey->class <= 16
and $found_arr->rt_arr->epoch - $now->epoch < 600 )
{
$self->app->add_wagonorder(
uid => $uid,
train_id => $journey->id,
is_arrival => 1,
eva => $arr,
datetime => $found_arr->sched_dep,
train_type => $journey->type,
train_no => $journey->number,
); );
$self->app->add_stationinfo( $uid, 0, $journey->id, if ( $entry->{backend_id} <= 1
$found_dep->loc->eva, $found_arr->loc->eva ); and $journey->class <= 16
and $found_arr->rt_arr->epoch - $now->epoch
< 600 )
{
$self->app->add_wagonorder(
uid => $uid,
train_id => $journey->id,
is_arrival => 1,
eva => $arr,
datetime => $found_arr->sched_dep,
train_type => $journey->type,
train_no => $journey->number,
);
$self->app->add_stationinfo( $uid, 0,
$journey->id, $found_dep->loc->eva,
$found_arr->loc->eva );
}
} }
} }
} )->catch(
)->catch( sub {
sub { my ($err) = @_;
my ($err) = @_; if ( $err
if ( $err =~ m{svcResL\[0\][.]err is (?:FAIL|PARAMETER)$} ) =~ m{svcResL\[0\][.]err is (?:FAIL|PARAMETER)$} )
{ {
# HAFAS do be weird. These are not actionable. # HAFAS do be weird. These are not actionable.
$self->app->log->debug("work($uid)/journey: $err"); $self->app->log->debug("work($uid)/journey: $err");
}
else {
$self->app->log->error("work($uid)/journey: $err");
}
} }
else {
$self->app->log->error("work($uid)/journey: $err");
}
}
)->wait;
if ( $arr
and $entry->{real_arr_ts}
and $now->epoch - $entry->{real_arr_ts} > 600 )
{
$self->app->checkout_p(
station => $arr,
force => 2,
dep_eva => $dep,
arr_eva => $arr,
uid => $uid
)->wait; )->wait;
if ( $arr
and $entry->{real_arr_ts}
and $now->epoch - $entry->{real_arr_ts} > 600 )
{
$self->app->checkout_p(
station => $arr,
force => 2,
dep_eva => $dep,
arr_eva => $arr,
uid => $uid
)->wait;
}
next;
};
if ($@) {
$errors += 1;
$self->app->log->error("work($uid)/hafas: $@");
} }
next;
} }
# TODO irgendwo ist hier ne race condition wo ein neuer checkin (in HAFAS) mit IRIS-Daten überschrieben wird. # TODO irgendwo ist hier ne race condition wo ein neuer checkin (in HAFAS) mit IRIS-Daten überschrieben wird.