Ignore jobs started over 50 minutes ago (setting: jobs_stale_after)

This commit is contained in:
Oliver Gorwits
2018-01-08 14:12:51 +00:00
parent eef519ef93
commit ac81f933d7
3 changed files with 18 additions and 3 deletions

View File

@@ -1,3 +1,9 @@
2.038007
[ENHANCEMENTS]
* Ignore jobs started over 50 minutes ago (setting: jobs_stale_after)
2.038006 2.038006
[BUG FIXES] [BUG FIXES]

View File

@@ -154,6 +154,7 @@ sub jq_getsome {
job => $job->id, job => $job->id,
-exists => $jobs->search({ -exists => $jobs->search({
status => { -like => 'queued-%' }, status => { -like => 'queued-%' },
started => \[q/> (now() - ?::interval)/, setting('jobs_stale_after')],
%job_properties, %job_properties,
})->as_query, })->as_query,
}], }],
@@ -170,8 +171,10 @@ sub jq_getsome {
sub jq_locked { sub jq_locked {
my @returned = (); my @returned = ();
my $rs = schema('netdisco')->resultset('Admin') my $rs = schema('netdisco')->resultset('Admin')->search({
->search({ status => ('queued-'. setting('workers')->{'BACKEND'}) }); status => ('queued-'. setting('workers')->{'BACKEND'}),
started => \[q/> (now() - ?::interval)/, setting('jobs_stale_after')],
});
while (my $job = $rs->next) { while (my $job = $rs->next) {
push @returned, App::Netdisco::Backend::Job->new({ $job->get_columns }); push @returned, App::Netdisco::Backend::Job->new({ $job->get_columns });
@@ -197,7 +200,10 @@ sub jq_lock {
try { try {
my $updated = schema('netdisco')->resultset('Admin') my $updated = schema('netdisco')->resultset('Admin')
->search({ job => $job->id, status => 'queued' }, { for => 'update' }) ->search({ job => $job->id, status => 'queued' }, { for => 'update' })
->update({ status => ('queued-'. setting('workers')->{'BACKEND'}) }); ->update({
status => ('queued-'. setting('workers')->{'BACKEND'}),
started => \"now()",
});
$happy = true if $updated > 0; $happy = true if $updated > 0;
} }

View File

@@ -284,6 +284,9 @@ workers:
retry_after: '7 days' retry_after: '7 days'
queue: PostgreSQL queue: PostgreSQL
# 50 minutes
jobs_stale_after: 3000
dns: dns:
max_outstanding: 50 max_outstanding: 50
hosts_file: '/etc/hosts' hosts_file: '/etc/hosts'