Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
ale
djrandom-py
Commits
c726994c
Commit
c726994c
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
stop using the global Stats singleton
parent
162960ae
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/djrandom_client/stats.py
+4
-5
4 additions, 5 deletions
client/djrandom_client/stats.py
client/djrandom_client/upload.py
+13
-10
13 additions, 10 deletions
client/djrandom_client/upload.py
with
17 additions
and
15 deletions
client/djrandom_client/stats.py
+
4
−
5
View file @
c726994c
...
...
@@ -25,8 +25,10 @@ class StatsDumperThread(threading.Thread):
class
Stats
(
object
):
"""
Thread-safe instrumentation.
"""
def
__init__
(
self
):
self
.
_path
=
os
.
path
.
join
(
os
.
getenv
(
'
HOME
'
),
'
.djrandom.state
'
)
def
__init__
(
self
,
path
=
None
):
if
not
path
:
path
=
os
.
path
.
expanduser
(
'
~/.djrandom.state
'
)
self
.
_path
=
path
self
.
_data
=
{}
self
.
_lock
=
threading
.
Lock
()
if
os
.
path
.
exists
(
self
.
_path
):
...
...
@@ -55,6 +57,3 @@ class Stats(object):
with
self
.
_lock
:
self
.
_data
[
key
]
=
value
# Global instance.
data
=
Stats
()
This diff is collapsed.
Click to expand it.
client/djrandom_client/upload.py
+
13
−
10
View file @
c726994c
...
...
@@ -60,12 +60,14 @@ class FileDatabase(object):
class
Uploader
(
threading
.
Thread
):
def
__init__
(
self
,
server_url
,
api_key
,
db
=
None
):
def
__init__
(
self
,
server_url
,
api_key
,
db_path
=
None
,
state_path
=
None
):
threading
.
Thread
.
__init__
(
self
)
self
.
api_key
=
api_key
self
.
server_url
=
server_url
self
.
queue
=
Queue
.
Queue
(
100
)
self
.
db_path
=
db
self
.
db_path
=
db_path
self
.
stats
=
stats
.
Stats
(
state_path
)
self
.
opener
=
urllib2
.
build_opener
(
throttle
.
ThrottledHTTPHandler
)
user_agent
=
'
djrandom_client/%s (%s %s Python/%s)
'
%
(
...
...
@@ -104,34 +106,35 @@ class Uploader(threading.Thread):
result
=
self
.
_get
(
'
/check/
'
+
sha1
)
if
result
:
log
.
info
(
'
%s already on server (%s)
'
%
(
path
,
sha1
))
return
True
return
result
=
self
.
_put
(
'
/upload/
'
+
sha1
,
path
)
if
not
result
:
raise
UploadError
(
'
er
ror uploading %s
'
%
path
)
s
tats
.
data
.
incr
(
'
uploaded_files
'
)
raise
UploadError
(
'
s
er
ver error
'
)
s
elf
.
stats
.
incr
(
'
uploaded_files
'
)
log
.
info
(
'
successfully uploaded %s (%s)
'
%
(
path
,
sha1
))
def
run
(
self
):
db
=
FileDatabase
(
self
.
db_path
)
try
:
while
True
:
s
tats
.
data
.
set
(
'
uploading
'
,
None
)
s
elf
.
stats
.
set
(
'
uploading
'
,
None
)
path
=
self
.
queue
.
get
()
if
path
is
None
:
break
if
db
.
has
(
path
):
continue
s
tats
.
data
.
set
(
'
uploading
'
,
path
)
s
elf
.
stats
.
set
(
'
uploading
'
,
path
)
try
:
self
.
upload
(
path
)
db
.
add
(
path
)
except
Exception
,
e
:
log
.
error
(
'
error uploading %s: %s
'
%
(
path
,
str
(
e
)))
s
tats
.
data
.
incr
(
'
errors
'
)
s
tats
.
data
.
set
(
'
last_error
'
,
str
(
e
))
s
tats
.
data
.
set
(
'
last_error_timestamp
'
,
'
%i
'
%
time
.
time
())
s
elf
.
stats
.
incr
(
'
errors
'
)
s
elf
.
stats
.
set
(
'
last_error
'
,
str
(
e
))
s
elf
.
stats
.
set
(
'
last_error_timestamp
'
,
'
%i
'
%
time
.
time
())
finally
:
log
.
debug
(
'
uploader thread exiting
'
)
self
.
stats
.
_save
()
db
.
close
()
def
stop
(
self
):
...
...
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