diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-07-23 20:18:10 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-07-23 20:18:10 +0200 |
commit | 38ad42b42cbf6da6254a2498a2fc553507cb3f18 (patch) | |
tree | aafcec15240e9804555e66cfb4af1ebccff823c9 /lib/Travelynx/Command/work.pm | |
parent | c0754f9e871e68019cd6109e8fc2649b515b9fc1 (diff) |
convert checkout to promises (checkout_p)
Diffstat (limited to 'lib/Travelynx/Command/work.pm')
-rw-r--r-- | lib/Travelynx/Command/work.pm | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm index 3086737..23d2925 100644 --- a/lib/Travelynx/Command/work.pm +++ b/lib/Travelynx/Command/work.pm @@ -86,15 +86,15 @@ sub run { # train. if ($checked_in) { - # check out (adds a cancelled journey and resets journey state - # to checkin - $self->app->checkout( + # check out (adds a cancelled journey and resets journey state + # to checkin + $self->app->checkout_p( station => $arr, - force => 1, + force => 2, dep_eva => $dep, arr_eva => $arr, uid => $uid - ); + )->wait; } } else { @@ -153,15 +153,15 @@ sub run { if ( $checked_in and $train->arrival_is_cancelled ) { - # check out (adds a cancelled journey and resets journey state - # to destination selection) - $self->app->checkout( + # check out (adds a cancelled journey and resets journey state + # to destination selection) + $self->app->checkout_p( station => $arr, force => 0, dep_eva => $dep, arr_eva => $arr, uid => $uid - ); + )->wait; } else { $self->app->add_route_timestamps( @@ -174,21 +174,24 @@ sub run { } } elsif ( $entry->{real_arr_ts} ) { - my ( undef, $error ) = $self->app->checkout( + my ( undef, $error ) = $self->app->checkout_p( station => $arr, - force => 1, + force => 2, dep_eva => $dep, arr_eva => $arr, uid => $uid - ); - if ($error) { - die("${error}\n"); - } + )->catch( + sub { + my ($error) = @_; + $self->app->log->error("work($uid)/arrival: $@"); + $errors += 1; + } + )->wait; } }; if ($@) { - $errors += 1; $self->app->log->error("work($uid)/arrival: $@"); + $errors += 1; } eval { } |