Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Roman Karwacik
website
Commits
26b16a86
Commit
26b16a86
authored
Jan 08, 2018
by
Andreas Valder
Browse files
fixes transaction deadlocks causing exceptions
parent
fccadfa4
Changes
1
Hide whitespace changes
Inline
Side-by-side
jobs.py
View file @
26b16a86
...
...
@@ -141,20 +141,25 @@ def jobs_schedule(hostname):
if
not
hostdata
:
return
'no hostdata sent'
,
400
job
=
None
tries
=
0
jobtypes
=
hostdata
[
'jobtypes'
]
if
'jobtypes'
in
hostdata
else
[]
while
(
not
job
):
query
(
"BEGIN"
)
for
i
in
query
(
'SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'
):
if
i
[
'type'
]
in
hostdata
[
'jobtypes'
]
and
\
i
[
'queue'
]
in
hostdata
[
'queues'
]:
job
=
i
break
if
not
job
:
return
'no jobs'
,
503
modify
(
'UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?'
,
hostname
,
datetime
.
now
(),
job
[
'id'
])
try
:
query
(
"BEGIN"
)
for
i
in
query
(
'SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'
):
if
i
[
'type'
]
in
hostdata
[
'jobtypes'
]
and
\
i
[
'queue'
]
in
hostdata
[
'queues'
]:
job
=
i
break
if
not
job
:
return
'no jobs'
,
503
modify
(
'UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?'
,
hostname
,
datetime
.
now
(),
job
[
'id'
])
query
(
"COMMIT"
)
except
:
except
OperationalError
:
tries
+=
1
job
=
None
sleep
(
random
.
randinti
(
0
,
50
))
if
tries
>
10
:
return
'no jobs'
,
503
return
Response
(
json
.
dumps
(
job
,
default
=
date_json_handler
),
mimetype
=
'application/json'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment