Properly catch errors loading minions

This commit is contained in:
Finn 2019-07-09 17:55:50 +01:00
parent 9c79e50eba
commit 1444574d26
No known key found for this signature in database
GPG key ID: 7455B4B17685B598
2 changed files with 12 additions and 7 deletions

View file

@ -19,7 +19,7 @@ sub import_csv {
my ($self) = @_; my ($self) = @_;
my $rows = $self->csv_data; my $rows = $self->csv_data;
my $lcc_org = $self->schema->resultset('Organisation')->find({ name => "Lancashire County Council" }); # my $lcc_org = $self->schema->resultset('Organisation')->find({ name => "Lancashire County Council" });
foreach my $row ( @{$rows} ) { foreach my $row ( @{$rows} ) {
$self->_row_to_result($row); $self->_row_to_result($row);
} }
@ -44,6 +44,8 @@ sub _row_to_result {
my $paid_date = ( $row->{paid_date} ? $date_formatter->parse_datetime($row->{paid_date}) : DateTime->today ); my $paid_date = ( $row->{paid_date} ? $date_formatter->parse_datetime($row->{paid_date}) : DateTime->today );
#my $distance = $self->get_distance_from_coords( $organisation, $lcc_org );
# TODO negative values are sometimes present # TODO negative values are sometimes present
$self->external_result->find_or_create_related('transactions', { $self->external_result->find_or_create_related('transactions', {
external_id => $row->{transaction_id}, external_id => $row->{transaction_id},
@ -53,10 +55,11 @@ sub _row_to_result {
purchase_time => $paid_date, purchase_time => $paid_date,
value => $row->{net_amount}, value => $row->{net_amount},
meta => { meta => {
gross_value => $row->{gross_amount}, gross_value => $row->{gross_amount} * 100000,
sales_tax_value => $row->{"vat amount"}, sales_tax_value => $row->{"vat amount"} * 100000,
net_value => $row->{net_amount}, net_value => $row->{net_amount} * 100000,
}, },
# distance => $distance,
} }
}); });
} }

View file

@ -15,11 +15,13 @@ sub register {
my $job_namespace = __PACKAGE__ . '::Job'; my $job_namespace = __PACKAGE__ . '::Job';
my @modules = find_modules $job_namespace; my @modules = find_modules $job_namespace;
for my $package ( @modules ) { for my $package ( @modules ) {
my ( $job ) = $package =~ /${job_namespace}::(.*)$/; my ( $job_name ) = $package =~ /${job_namespace}::(.*)$/;
$app->log->debug( $package ); $app->log->debug( $package );
load_class $package; if (my $e = load_class $package) {
die ref $e ? "Exception: $e" : "$package not found";
}
$app->minion->add_task( $app->minion->add_task(
$job => sub { $job_name => sub {
my ( $job, @args ) = @_; my ( $job, @args ) = @_;
my $job_runner = $package->new( my $job_runner = $package->new(
job => $job, job => $job,