Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
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
AURA
tank
Commits
af5cf073
Commit
af5cf073
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
job.Start() now accepts a parent context
parent
f25a011f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/v1/api_files.go
+3
-1
3 additions, 1 deletion
api/v1/api_files.go
importer/job.go
+3
-3
3 additions, 3 deletions
importer/job.go
with
6 additions
and
4 deletions
api/v1/api_files.go
+
3
−
1
View file @
af5cf073
...
...
@@ -29,6 +29,7 @@ import (
"net/http"
"net/url"
"time"
"context"
"github.com/gorilla/mux"
"gitlab.servus.at/autoradio/tank/importer"
...
...
@@ -83,7 +84,7 @@ func (api *API) CreateFileForGroup() http.Handler {
sendError
(
w
,
err
)
return
}
if
err
=
job
.
Start
(
3
*
time
.
Hour
);
err
!=
nil
{
// TODO: hardcoded value
if
err
=
job
.
Start
(
context
.
Background
(),
3
*
time
.
Hour
);
err
!=
nil
{
// TODO: hardcoded value
// shall we remove the file here... thinking...
sendError
(
w
,
err
)
return
...
...
@@ -123,6 +124,7 @@ func (api *API) PatchFileOfGroup() http.Handler {
return
}
// TODO: warn if data contains invalid/unknown keys
// TODO: only allow this for successfully imported files...!?
file
,
err
:=
api
.
store
.
UpdateFileMetadata
(
vars
[
"group-id"
],
id
,
data
)
if
err
!=
nil
{
sendError
(
w
,
err
)
...
...
This diff is collapsed.
Click to expand it.
importer/job.go
+
3
−
3
View file @
af5cf073
...
...
@@ -84,7 +84,7 @@ func (job *Job) run() (err error) {
return
}
func
(
job
*
Job
)
Start
(
timeout
time
.
Duration
)
error
{
func
(
job
*
Job
)
Start
(
ctx
context
.
Context
,
timeout
time
.
Duration
)
error
{
if
!
atomic
.
CompareAndSwapUint32
((
*
uint32
)(
&
job
.
State
),
uint32
(
JobNew
),
uint32
(
JobInitializing
))
{
if
atomic
.
LoadUint32
((
*
uint32
)(
&
job
.
State
))
==
uint32
(
JobCanceled
)
{
// the job has already been canceled and thus should just be removed from the inventory
...
...
@@ -96,9 +96,9 @@ func (job *Job) Start(timeout time.Duration) error {
// shall we use a global context here so we can cancel all jobs at once? i.e. for forced shutdown...
if
timeout
>
0
{
job
.
ctx
,
job
.
cancel
=
context
.
WithTimeout
(
c
ontext
.
Background
()
,
timeout
)
job
.
ctx
,
job
.
cancel
=
context
.
WithTimeout
(
c
tx
,
timeout
)
}
else
{
job
.
ctx
,
job
.
cancel
=
context
.
WithCancel
(
c
ontext
.
Background
()
)
job
.
ctx
,
job
.
cancel
=
context
.
WithCancel
(
c
tx
)
}
// from here on we need to take care that job.cancel() will be called in any case so that resources
// allocated by job.ctx are freed up.
...
...
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