Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
website
Commits
00595393
Commit
00595393
authored
Nov 09, 2016
by
Andreas Valder
Browse files
added ping and schedule api
parent
aea98511
Changes
1
Hide whitespace changes
Inline
Side-by-side
jobs.py
View file @
00595393
from
server
import
*
import
traceback
import
json
import
random
@
app
.
route
(
'/jobs/overview'
)
@
register_navbar
(
'Jobs'
,
iconlib
=
'fa'
,
icon
=
'suitcase'
)
...
...
@@ -31,11 +32,18 @@ def date_json_handler(obj):
@
app
.
route
(
'/jobs/api/ping'
,
methods
=
[
'GET'
,
'POST'
])
@
jobs_api_token_required
def
jobs_ping
():
def
jobs_
worker_
ping
():
hostname
=
request
.
values
[
'host'
]
query
(
'INSERT OR REPLACE INTO worker (hostname, last_ping) values (?, ?)'
,
hostname
,
datetime
.
now
())
return
'OK'
,
200
@
app
.
route
(
'/jobs/api/job/<id>/ping'
,
methods
=
[
'GET'
,
'POST'
])
@
jobs_api_token_required
def
jobs_ping
(
id
):
hostname
=
request
.
values
[
'host'
]
query
(
'UPDATE jobs SET worker = ?, last_ping = ? where id = ?'
,
hostname
,
datetime
.
now
(),
id
)
return
'OK'
,
200
@
app
.
route
(
'/jobs/api/schedule'
,
methods
=
[
'POST'
])
@
jobs_api_token_required
def
jobs_schedule
():
...
...
@@ -43,9 +51,18 @@ def jobs_schedule():
print
(
hostdata
)
if
not
hostdata
:
return
'no data'
,
500
job
=
None
jobtypes
=
hostdata
[
'jobtypes'
]
if
'jobtypes'
in
hostdata
else
[]
for
i
in
query
(
'SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'
):
if
i
[
'type'
]
in
hostdata
[
'jobtypes'
].
split
(
','
):
job
=
i
break
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'
].
split
(
','
):
job
=
i
break
modify
(
'UPDATE jobs SET state="running", worker = ? WHERE id = ?'
,
hostdata
[
'host'
],
job
[
'id'
])
try
:
query
(
"COMMIT"
)
except
:
job
=
None
sleep
(
random
.
randinti
(
0
,
50
))
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