Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hidra
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
steinbac
hidra
Commits
626b4210
Commit
626b4210
authored
9 years ago
by
Manuela Kuhn
Browse files
Options
Downloads
Patches
Plain Diff
Prevent multiple redundant entries in ringbuffer
parent
68d61b4b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/shared/RingBuffer.py
+38
-31
38 additions, 31 deletions
src/shared/RingBuffer.py
with
38 additions
and
31 deletions
src/shared/RingBuffer.py
+
38
−
31
View file @
626b4210
...
...
@@ -108,38 +108,45 @@ class RingBuffer:
def
add
(
self
,
filename
,
fileModTime
,
fileContent
=
False
):
if
fileContent
and
self
.
storeContent
:
# prepend file to ring buffer and restore order
self
.
ringBuffer
[:
0
]
=
[[
fileModTime
,
filename
,
fileContent
]]
self
.
ringBuffer
=
sorted
(
self
.
ringBuffer
,
reverse
=
True
)
# if the maximal size is exceeded: remove the oldest files
if
len
(
self
.
ringBuffer
)
>
self
.
maxRingBufferSize
:
for
mod_time
,
path
,
content
in
self
.
ringBuffer
[
self
.
maxRingBufferSize
:]:
self
.
log
.
debug
(
"
Remove file from ring buffer:
"
+
str
(
path
)
)
# os.remove(path)
self
.
ringBuffer
.
remove
([
mod_time
,
path
,
content
])
# prevents to store files multiple times (e.g. if event was thrown multiple times for one file)
if
[
fileModTime
,
filename
]
in
self
.
ringBuffer
:
self
.
log
.
info
(
"
File already contained in ring buffer:
"
+
str
(
filename
)
)
else
:
# prepend file to ring buffer and restore order
self
.
ringBuffer
[:
0
]
=
[[
fileModTime
,
filename
,
fileContent
]]
self
.
ringBuffer
=
sorted
(
self
.
ringBuffer
,
reverse
=
True
)
# if the maximal size is exceeded: remove the oldest files
if
len
(
self
.
ringBuffer
)
>
self
.
maxRingBufferSize
:
for
mod_time
,
path
,
content
in
self
.
ringBuffer
[
self
.
maxRingBufferSize
:]:
self
.
log
.
debug
(
"
Remove file from ring buffer:
"
+
str
(
path
)
)
self
.
ringBuffer
.
remove
([
mod_time
,
path
,
content
])
else
:
# prepend file to ring buffer and restore order
self
.
ringBuffer
[:
0
]
=
[[
fileModTime
,
filename
]]
self
.
ringBuffer
=
sorted
(
self
.
ringBuffer
,
reverse
=
True
)
# if the maximal size is exceeded: remove the oldest files
if
len
(
self
.
ringBuffer
)
>
self
.
maxRingBufferSize
:
for
mod_time
,
path
in
self
.
ringBuffer
[
self
.
maxRingBufferSize
:]:
if
len
(
self
.
dataQueue
)
>=
self
.
maxQueueSize
:
oldFile
=
self
.
dataQueue
.
pop
()
self
.
log
.
debug
(
"
Remove file from disc:
"
+
str
(
oldFile
)
)
try
:
os
.
remove
(
oldFile
)
except
Exception
as
e
:
self
.
log
.
debug
(
"
Unable to remove file from disc:
"
+
str
(
oldFile
)
)
self
.
log
.
debug
(
"
Error was:
"
+
str
(
e
)
)
self
.
log
.
debug
(
"
Remove file from ring buffer:
"
+
str
(
path
)
)
self
.
ringBuffer
.
remove
([
mod_time
,
path
])
self
.
dataQueue
.
appendleft
(
path
)
self
.
log
.
debug
(
"
Adding File to Queue:
"
+
str
(
path
)
)
# prevents to store files multiple times (e.g. if event was thrown multiple times for one file)
if
[
fileModTime
,
filename
]
in
self
.
ringBuffer
:
self
.
log
.
info
(
"
File already contained in ring buffer:
"
+
str
(
filename
)
)
else
:
# prepend file to ring buffer and restore order
self
.
ringBuffer
[:
0
]
=
[[
fileModTime
,
filename
]]
self
.
ringBuffer
=
sorted
(
self
.
ringBuffer
,
reverse
=
True
)
# if the maximal size is exceeded: remove the oldest files
if
len
(
self
.
ringBuffer
)
>
self
.
maxRingBufferSize
:
for
mod_time
,
path
in
self
.
ringBuffer
[
self
.
maxRingBufferSize
:]:
if
len
(
self
.
dataQueue
)
>=
self
.
maxQueueSize
:
oldFile
=
self
.
dataQueue
.
pop
()
self
.
log
.
debug
(
"
Remove file from disc:
"
+
str
(
oldFile
)
)
try
:
os
.
remove
(
oldFile
)
except
Exception
as
e
:
self
.
log
.
debug
(
"
Unable to remove file from disc:
"
+
str
(
oldFile
)
)
self
.
log
.
debug
(
"
Error was:
"
+
str
(
e
)
)
self
.
log
.
debug
(
"
Remove file from ring buffer:
"
+
str
(
path
)
)
self
.
ringBuffer
.
remove
([
mod_time
,
path
])
self
.
dataQueue
.
appendleft
(
path
)
self
.
log
.
debug
(
"
Adding File to Queue:
"
+
str
(
path
)
)
def
removeAll
(
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