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
68ea7cac
Commit
68ea7cac
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
improved signaling for attached sources
parent
220a9146
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/v1/api_imports.go
+6
-4
6 additions, 4 deletions
api/v1/api_imports.go
importer/fetch.go
+6
-1
6 additions, 1 deletion
importer/fetch.go
importer/job.go
+6
-5
6 additions, 5 deletions
importer/job.go
importer/types.go
+3
-2
3 additions, 2 deletions
importer/types.go
with
21 additions
and
12 deletions
api/v1/api_imports.go
+
6
−
4
View file @
68ea7cac
...
...
@@ -74,13 +74,15 @@ func (api *API) UploadFile() http.Handler {
return
}
if
err
=
job
.
AttachSource
(
uint64
(
r
.
ContentLength
),
r
.
Body
);
err
!=
nil
{
done
,
err
:=
job
.
AttachSource
(
uint64
(
r
.
ContentLength
),
r
.
Body
)
if
err
!=
nil
{
sendError
(
w
,
err
)
return
}
if
err
=
<-
done
;
err
!=
nil
{
sendError
(
w
,
err
)
return
}
<-
job
.
Done
()
// TODO: get result from job
sendWebResponse
(
w
,
http
.
StatusOK
,
nil
)
})
}
...
...
This diff is collapsed.
Click to expand it.
importer/fetch.go
+
6
−
1
View file @
68ea7cac
...
...
@@ -59,7 +59,9 @@ func (job *Job) prepareSource() {
// simulate a 10 MB file...
l
:=
uint64
(
10
*
1024
*
1024
)
r
:=
devNull
(
l
)
atomic
.
StorePointer
((
*
unsafe
.
Pointer
)(
unsafe
.
Pointer
(
&
job
.
source
)),
unsafe
.
Pointer
(
&
JobSource
{
l
,
&
r
}))
src
:=
&
JobSource
{
len
:
l
,
r
:
&
r
}
src
.
done
=
make
(
chan
error
,
1
)
atomic
.
StorePointer
((
*
unsafe
.
Pointer
)(
unsafe
.
Pointer
(
&
job
.
source
)),
unsafe
.
Pointer
(
src
))
close
(
job
.
subC
.
sourceAttached
)
}
}
...
...
@@ -89,6 +91,8 @@ func (job *Job) fetch() error {
case
<-
job
.
subC
.
sourceAttached
:
}
// job.source is now initialized and points to a valid source
// make sure a potentially connected source gets notified in any case
defer
close
(
job
.
source
.
done
)
conv
,
err
:=
job
.
newConverter
()
if
err
!=
nil
{
...
...
@@ -119,5 +123,6 @@ func (job *Job) fetch() error {
}
job
.
Progress
.
set
(
StepFetching
,
1
)
job
.
source
.
done
<-
err
return
err
}
This diff is collapsed.
Click to expand it.
importer/job.go
+
6
−
5
View file @
68ea7cac
...
...
@@ -145,17 +145,18 @@ func (job *Job) Start(ctx context.Context, timeout time.Duration) error {
return
nil
}
func
(
job
*
Job
)
AttachSource
(
length
uint64
,
r
io
.
Reader
)
error
{
func
(
job
*
Job
)
AttachSource
(
length
uint64
,
r
io
.
Reader
)
(
<-
chan
error
,
error
)
{
if
state
:=
atomic
.
LoadUint32
((
*
uint32
)(
&
job
.
State
));
state
!=
uint32
(
JobRunning
)
{
return
ErrImportNotRunning
return
nil
,
ErrImportNotRunning
}
src
:=
&
JobSource
{
length
,
r
}
src
:=
&
JobSource
{
len
:
length
,
r
:
r
}
src
.
done
=
make
(
chan
error
,
1
)
if
ok
:=
atomic
.
CompareAndSwapPointer
((
*
unsafe
.
Pointer
)(
unsafe
.
Pointer
(
&
job
.
source
)),
unsafe
.
Pointer
(
nil
),
unsafe
.
Pointer
(
src
));
!
ok
{
return
ErrSourceAlreadyAttached
return
nil
,
ErrSourceAlreadyAttached
}
close
(
job
.
subC
.
sourceAttached
)
return
nil
return
src
.
done
,
nil
}
func
(
job
*
Job
)
Cancel
()
{
...
...
This diff is collapsed.
Click to expand it.
importer/types.go
+
3
−
2
View file @
68ea7cac
...
...
@@ -75,8 +75,9 @@ func (s *SourceURL) UnmarshalText(data []byte) (err error) {
//******* Source
type
JobSource
struct
{
len
uint64
r
io
.
Reader
len
uint64
r
io
.
Reader
done
chan
error
}
//******* State
...
...
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