summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Command
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Travelynx/Command')
-rw-r--r--lib/Travelynx/Command/database.pm26
-rw-r--r--lib/Travelynx/Command/work.pm45
2 files changed, 68 insertions, 3 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index 59e41d9..e92dd4b 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -1012,6 +1012,32 @@ my @migrations = (
}
);
},
+
+ # v21 -> v22
+ sub {
+ my ($db) = @_;
+ $db->query(
+ qq{
+ create table traewelling (
+ user_id integer not null references users (id) primary key,
+ email varchar(256) not null,
+ push_sync boolean not null,
+ pull_sync boolean not null,
+ errored boolean,
+ token text,
+ data jsonb,
+ latest_run timestamptz
+ );
+ comment on table traewelling is 'Token and Status for Traewelling';
+ create view traewelling_str as select
+ user_id, email, push_sync, pull_sync, errored, token, data,
+ extract(epoch from latest_run) as latest_run_ts
+ from traewelling
+ ;
+ update schema_version set version = 22;
+ }
+ );
+ },
);
sub setup_db {
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;