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
Wiki
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
Roman Karwacik
website
Commits
6b930170
Commit
6b930170
authored
7 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Implemented job canceling
parent
1ec90e26
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
db_schema.sql
+2
-1
2 additions, 1 deletion
db_schema.sql
jobs.py
+18
-8
18 additions, 8 deletions
jobs.py
server.py
+1
-1
1 addition, 1 deletion
server.py
templates/jobs_overview.html
+7
-1
7 additions, 1 deletion
templates/jobs_overview.html
with
28 additions
and
11 deletions
db_schema.sql
+
2
−
1
View file @
6b930170
...
...
@@ -296,7 +296,8 @@ CREATE TABLE IF NOT EXISTS `jobs` (
`last_ping`
datetime
NOT
NULL
DEFAULT
''
,
`worker`
text
DEFAULT
NULL
,
`data`
text
NOT
NULL
DEFAULT
'{}'
,
`status`
text
NOT
NULL
DEFAULT
'{}'
`status`
text
NOT
NULL
DEFAULT
'{}'
,
`canceled`
INTEGER
DEFAULT
0
);
CREATE
TABLE
IF
NOT
EXISTS
`responsible`
(
...
...
This diff is collapsed.
Click to expand it.
jobs.py
+
18
−
8
View file @
6b930170
...
...
@@ -18,9 +18,16 @@ def job_handler(*types, state='finished'):
def
schedule_job
(
jobtype
,
data
=
None
,
priority
=
0
,
queue
=
"
default
"
):
if
not
data
:
data
=
{}
modify
(
'
INSERT INTO jobs (type, priority, queue, data, time_created) VALUES (?, ?, ?, ?, ?)
'
,
return
modify
(
'
INSERT INTO jobs (type, priority, queue, data, time_created) VALUES (?, ?, ?, ?, ?)
'
,
jobtype
,
priority
,
queue
,
json
.
dumps
(
data
,
default
=
date_json_handler
),
datetime
.
now
())
def
cancel_job
(
job_id
):
modify
(
'
UPDATE jobs SET state =
"
deleted
"
WHERE id = ? AND state =
"
ready
"'
,
job_id
)
modify
(
'
UPDATE jobs SET canceled = 1 WHERE id = ?
'
,
job_id
)
def
restart_job
(
job_id
):
modify
(
'
UPDATE jobs SET state =
"
ready
"
WHERE id = ? AND state =
"
failed
"
AND NOT canceled
'
,
job_id
)
@app.route
(
'
/internal/jobs/overview
'
)
@register_navbar
(
'
Jobs
'
,
iconlib
=
'
fa
'
,
icon
=
'
suitcase
'
)
@mod_required
...
...
@@ -61,12 +68,12 @@ def jobs_action(action, jobid=None):
query
(
'
UPDATE jobs SET state=
"
deleted
"
WHERE state =
"
failed
"
AND (id = ? OR ? IS NULL)
'
,
jobid
,
jobid
)
elif
action
==
'
retry_failed
'
:
query
(
'
UPDATE jobs SET state=
"
ready
"
WHERE state =
"
failed
"
AND (id = ? OR ? IS NULL)
'
,
jobid
,
jobid
)
elif
action
==
'
copy
'
:
if
jobid
:
elif
action
==
'
copy
'
and
jobid
:
query
(
"
INSERT INTO jobs SELECT NULL, type, priority, queue,
'
ready
'
,
''
,
''
, ?,
''
, NULL, data,
'
{}
'
FROM jobs where ID=?;
"
,
datetime
.
now
(),
jobid
)
elif
action
==
'
delete
'
:
if
jobid
:
elif
action
==
'
delete
'
and
jobid
:
query
(
'
UPDATE jobs SET state=
"
deleted
"
WHERE id = ?
'
,
jobid
)
elif
action
==
'
cancel
'
and
jobid
:
cancel_job
(
jobid
)
return
redirect
(
request
.
values
.
get
(
'
ref
'
,
url_for
(
'
jobs_overview
'
)))
def
jobs_api_token_required
(
func
):
...
...
@@ -118,6 +125,9 @@ def jobs_ping(id):
func
(
id
,
job
[
'
type
'
],
json
.
loads
(
job
[
'
data
'
]),
state
,
json
.
loads
(
job
[
'
status
'
]))
except
Exception
:
traceback
.
print_exc
()
if
job
[
'
canceled
'
]:
return
'
Job canceled
'
,
205
else
:
return
'
OK
'
,
200
@app.route
(
'
/internal/jobs/api/worker/<hostname>/schedule
'
,
methods
=
[
'
POST
'
])
...
...
This diff is collapsed.
Click to expand it.
server.py
+
1
−
1
View file @
6b930170
...
...
@@ -486,7 +486,7 @@ def dbstatus():
def
date_json_handler
(
obj
):
return
obj
.
isoformat
()
if
hasattr
(
obj
,
'
isoformat
'
)
else
obj
from
jobs
import
job_handler
,
schedule_job
from
jobs
import
job_handler
,
schedule_job
,
cancel_job
,
restart_job
from
edit
import
edit_handler
import
feeds
import
importer
...
...
This diff is collapsed.
Click to expand it.
templates/jobs_overview.html
+
7
−
1
View file @
6b930170
...
...
@@ -192,7 +192,7 @@
<td>
{{i.priority}}
</td>
<td>
{{i.worker}}
</td>
<td>
{{i.last_ping}}
</td>
<td>
{{i.state}}
</td>
<td>
{{i.state}}
{% if i.canceled %} (canceled) {% endif %}
</td>
<td>
{{i.time_created}}
</td>
<td>
{{i.time_finished}}
</td>
<td>
{{i.time_scheduled}}
</td>
...
...
@@ -223,6 +223,12 @@
<span
class=
"glyphicon glyphicon-trash"
aria-hidden=
"true"
></span>
</a>
</li>
{% elif i.state == "running" %}
<li>
<a
class=
"btn btn-default"
{%
if
i.canceled
%}
disabled=
"disabled"
{%
endif
%}
href=
"{{url_for('jobs_action', action='cancel', jobid=i.id, ref=request.url)}}"
title=
"Abbrechen"
style=
"background-color: red;"
>
<span
class=
"glyphicon glyphicon-stop"
aria-hidden=
"true"
></span>
</a>
</li>
{% endif %}
{% endif %}
</ul>
...
...
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