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
01f16260
Commit
01f16260
authored
6 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
sync import state with store
parent
2651c690
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
importer/job.go
+8
-6
8 additions, 6 deletions
importer/job.go
store/files.go
+12
-0
12 additions, 0 deletions
store/files.go
with
20 additions
and
6 deletions
importer/job.go
+
8
−
6
View file @
01f16260
...
...
@@ -29,6 +29,8 @@ import (
"net/url"
"sync/atomic"
"time"
"gitlab.servus.at/autoradio/tank/store"
)
type
Job
struct
{
...
...
@@ -55,18 +57,18 @@ func (job *Job) run() (err error) {
job
.
StartedAt
=
time
.
Now
()
job
.
im
.
dbgLog
.
Printf
(
"running import for %s/%d from: %s"
,
job
.
Group
,
job
.
ID
,
job
.
Source
.
String
())
// TODO: update store.file: set i
mport
s
tate
to
ImportRunning
job
.
im
.
store
.
UpdateFileI
mport
S
tate
(
job
.
Group
,
job
.
ID
,
store
.
ImportRunning
,
false
)
if
err
=
job
.
fetch
();
err
!=
nil
{
// update store.file: set i
mport
s
tate
to
ImportAborted
+ success =
false
job
.
im
.
store
.
UpdateFileI
mport
S
tate
(
job
.
Group
,
job
.
ID
,
store
.
ImportAborted
,
false
)
// send result to all done subscriptions
return
err
}
if
err
=
job
.
normalize
();
err
!=
nil
{
// update store.file: set i
mport
s
tate
to
ImportAborted
+ success =
false
job
.
im
.
store
.
UpdateFileI
mport
S
tate
(
job
.
Group
,
job
.
ID
,
store
.
ImportAborted
,
false
)
// send result to all done subscriptions
return
err
}
// update store.file: set i
mport
s
tate
to ImportDone + success =
true
job
.
im
.
store
.
UpdateFileI
mport
S
tate
(
job
.
Group
,
job
.
ID
,
store
.
ImportDone
,
true
)
// send result to all done subscriptions
return
}
...
...
@@ -80,7 +82,7 @@ func (job *Job) start() <-chan error {
return
done
}
// handle subscriptions
for progress and
done
//
TODO:
handle subscriptions
to
done
func
(
job
*
Job
)
Start
(
timeout
time
.
Duration
)
error
{
if
!
atomic
.
CompareAndSwapUint32
((
*
uint32
)(
&
job
.
State
),
uint32
(
JobNew
),
uint32
(
JobInitializing
))
{
...
...
@@ -101,7 +103,7 @@ func (job *Job) Start(timeout time.Duration) error {
job
.
cleanup
()
return
ErrTooManyJobs
}
// TODO: update store.file: set i
mport
s
tate
to
ImportPending
job
.
im
.
store
.
UpdateFileI
mport
S
tate
(
job
.
Group
,
job
.
ID
,
store
.
ImportPending
,
false
)
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
store/files.go
+
12
−
0
View file @
01f16260
...
...
@@ -88,6 +88,18 @@ func (st *Store) UpdateFileMetadata(group string, id uint64, metadata map[string
return
file
,
nil
}
func
(
st
*
Store
)
UpdateFileImportState
(
group
string
,
id
uint64
,
state
ImportState
,
success
bool
)
(
*
File
,
error
)
{
file
:=
&
File
{
ID
:
id
}
is
:=
make
(
map
[
string
]
interface
{})
is
[
"source__import__state"
]
=
state
is
[
"source__import__success"
]
=
success
if
err
:=
st
.
db
.
Model
(
&
file
)
.
Where
(
"group_name = ?"
,
group
)
.
Update
(
is
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
file
,
nil
}
func
(
st
*
Store
)
getFileUsage
(
id
uint64
,
playlists
*
Playlists
)
(
err
error
)
{
sub
:=
st
.
db
.
Model
(
PlaylistEntry
{})
.
Select
(
"playlist_id"
)
.
Where
(
"file_id = ?"
,
id
)
.
Group
(
"playlist_id"
)
.
SubQuery
()
err
=
st
.
db
.
Where
(
"id in ?"
,
sub
)
.
Find
(
playlists
)
.
Error
...
...
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