summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command/work.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-09-30 19:12:29 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-09-30 19:12:29 +0200
commit89e709d8d593939ab528b81d125fd37d303c4fa9 (patch)
tree574a0fbe6b6b0849d878c228e1f6b84e2c29d878 /lib/Travelynx/Command/work.pm
parent952740969ca9fa74c893dfe0961d3ae55ec9e85b (diff)
Allow linking a Träwelling account, auto-sync Träwelling→travelynx
travelynx→Träwelling is still work-in-progress Squashed commit of the following: commit 97faa6e2e6c8d20fba30f2d0f6e78187ceeb72e6 Author: Daniel Friesel <derf@finalrewind.org> Date: Wed Sep 30 18:50:05 2020 +0200 improve traewelling log and tx handling commit 487d7dd728b9d45b731bdc7098cf3358ea2e206e Author: Daniel Friesel <derf@finalrewind.org> Date: Wed Sep 30 18:02:41 2020 +0200 add missing traewelling template commit 0148da2f48d9a52dcddc0ab81f83d8f8ac3062ab Author: Daniel Friesel <derf@finalrewind.org> Date: Wed Sep 30 18:02:35 2020 +0200 improve traewelling pull sync commit 4861a9750f9f2d7621043361d0af6b0a8869a0df Author: Daniel Friesel <derf@finalrewind.org> Date: Tue Sep 29 22:14:24 2020 +0200 wip checkin from traewelling commit f6aeb6f06998a2a7a80f63a7b1b688b1a26b66bd Author: Daniel Friesel <derf@finalrewind.org> Date: Tue Sep 29 18:37:53 2020 +0200 refactor traewelling integration. login and logout are less of a hack now. checkin and checkout are not supported at the moment.
Diffstat (limited to 'lib/Travelynx/Command/work.pm')
-rw-r--r--lib/Travelynx/Command/work.pm45
1 files changed, 42 insertions, 3 deletions
diff --git a/lib/Travelynx/Command/work.pm b/lib/Travelynx/Command/work.pm
index 9c870d8..593735f 100644
--- a/lib/Travelynx/Command/work.pm
+++ b/lib/Travelynx/Command/work.pm
@@ -108,7 +108,11 @@ sub run {
# check out (adds a cancelled journey and resets journey state
# to checkin
- $self->app->checkout( $arr, 1, $uid );
+ $self->app->checkout(
+ station => $arr,
+ force => 1,
+ uid => $uid
+ );
}
}
else {
@@ -201,7 +205,11 @@ sub run {
{
# check out (adds a cancelled journey and resets journey state
# to destination selection)
- $self->app->checkout( $arr, 0, $uid );
+ $self->app->checkout(
+ station => $arr,
+ force => 0,
+ uid => $uid
+ );
}
}
else {
@@ -209,7 +217,11 @@ sub run {
}
}
elsif ( $entry->{real_arr_ts} ) {
- my ( undef, $error ) = $self->app->checkout( $arr, 1, $uid );
+ my ( undef, $error ) = $self->app->checkout(
+ station => $arr,
+ force => 1,
+ uid => $uid
+ );
if ($error) {
die("${error}\n");
}
@@ -222,6 +234,31 @@ sub run {
eval { }
}
+ for my $account_data ( $self->app->traewelling->get_pull_accounts ) {
+
+ # $account_data->{user_id} is the travelynx uid
+ # $account_data->{user_name} is the Träwelling username
+ $self->app->log->debug(
+ "Pulling Traewelling status for UID $account_data->{user_id}");
+ $self->app->traewelling_api->get_status_p(
+ username => $account_data->{data}{user_name},
+ token => $account_data->{token}
+ )->then(
+ sub {
+ my ($traewelling) = @_;
+ $self->app->traewelling_to_travelynx(
+ traewelling => $traewelling,
+ user_data => $account_data
+ );
+ }
+ )->catch(
+ sub {
+ my ($err) = @_;
+ $self->app->log->debug("Error $err");
+ }
+ )->wait;
+ }
+
# Computing yearly stats may take a while, but we've got all time in the
# world here. This means users won't have to wait when loading their
# own by-year journey log.
@@ -232,6 +269,8 @@ sub run {
year => $now->year
);
}
+
+ # TODO wait until all background jobs have terminated
}
1;