Fix: Processing result of running imapsync command

There was a possibility the status is_running never set back to 0.
Also the unlock command could be executed twice.
master
hunter-nl 2019-05-05 13:15:34 +02:00 committed by GitHub
parent b7b532768c
commit 54a039fbd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -154,17 +154,21 @@ while ($row = $sth->fetchrow_arrayref()) {
run [@$generated_cmds, @$custom_params_ref], '&>', \my $stdout; run [@$generated_cmds, @$custom_params_ref], '&>', \my $stdout;
$update = $dbh->prepare("UPDATE imapsync SET returned_text = ?, last_run = NOW(), is_running = 0 WHERE id = ?"); $update = $dbh->prepare("UPDATE imapsync SET returned_text = ? WHERE id = ?");
$update->bind_param( 1, ${stdout} ); $update->bind_param( 1, ${stdout} );
$update->bind_param( 2, ${id} ); $update->bind_param( 2, ${id} );
$update->execute(); $update->execute();
} catch { } catch {
$update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync', last_run = NOW(), is_running = 0 WHERE id = ?"); $update = $dbh->prepare("UPDATE imapsync SET returned_text = 'Could not start or finish imapsync' WHERE id = ?");
$update->bind_param( 1, ${id} );
$update->execute();
} finally {
$update = $dbh->prepare("UPDATE imapsync SET last_run = NOW(), is_running = 0 WHERE id = ?");
$update->bind_param( 1, ${id} ); $update->bind_param( 1, ${id} );
$update->execute(); $update->execute();
$lockmgr->unlock($lock_file);
}; };
} }
$sth->finish(); $sth->finish();