Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Video AG Infrastruktur
website
Commits
00595393
Commit
00595393
authored
8 years ago
by
Andreas Valder
Browse files
Options
Downloads
Patches
Plain Diff
added ping and schedule api
parent
aea98511
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
jobs.py
+22
-5
22 additions, 5 deletions
jobs.py
with
22 additions
and
5 deletions
jobs.py
+
22
−
5
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
[]
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
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment