Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Stingray
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
LOFAR2.0
Stingray
Commits
60008e88
Commit
60008e88
authored
7 months ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Optimisation for not reading the full list
parent
6e5830d1
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lofar_stingray/reader/_s3_packet_loader.py
+12
-11
12 additions, 11 deletions
lofar_stingray/reader/_s3_packet_loader.py
with
12 additions
and
11 deletions
lofar_stingray/reader/_s3_packet_loader.py
+
12
−
11
View file @
60008e88
...
...
@@ -10,6 +10,7 @@ import json
import
logging
from
datetime
import
datetime
,
timedelta
import
time
from
typing
import
Generator
from
minio
import
Minio
import
minio.datatypes
...
...
@@ -43,20 +44,20 @@ class S3PacketLoader: # pylint: disable=too-few-public-methods
self
.
prefix
=
prefix
.
strip
(
"
/
"
)
self
.
block_duration
=
block_duration
def
_list_objects_after
(
self
,
timestamp
:
datetime
)
->
list
[
minio
.
datatypes
.
Object
]:
def
_list_objects_after
(
self
,
timestamp
:
datetime
)
->
Generator
[
minio
.
datatypes
.
Object
,
None
,
None
]:
"""
Return a list of objects that (should) contain packets of and after
the given timestamp.
"""
# NB: The timestamp in the filename is the time when the file was
# completed, so after the last timestamp recorded in the file.
return
list
(
self
.
_minio_client
.
list_objects
(
self
.
bucket
,
recursive
=
True
,
prefix
=
f
"
{
self
.
prefix
}
"
,
start_after
=
f
"
{
self
.
prefix
}
/
{
timestamp
.
year
}
/
{
timestamp
.
month
:
02
d
}
/
"
f
"
{
timestamp
.
day
:
02
d
}
/
{
timestamp
.
isoformat
()
}
.json
"
,
)
return
self
.
_minio_client
.
list_objects
(
self
.
bucket
,
recursive
=
True
,
prefix
=
f
"
{
self
.
prefix
}
"
,
start_after
=
f
"
{
self
.
prefix
}
/
{
timestamp
.
year
}
/
{
timestamp
.
month
:
02
d
}
/
"
f
"
{
timestamp
.
day
:
02
d
}
/
{
timestamp
.
isoformat
()
}
.json
"
,
)
def
wait_for_packets
(
self
,
timestamp
:
datetime
)
->
bool
:
...
...
@@ -65,7 +66,7 @@ class S3PacketLoader: # pylint: disable=too-few-public-methods
Returns whether such packets were found.
"""
# if the packets are there, always return True
if
self
.
_list_objects_after
(
timestamp
):
if
next
(
self
.
_list_objects_after
(
timestamp
)
,
False
)
:
logger
.
info
(
"
wait_for_packets: Requested timestamp are available at startup
"
)
...
...
@@ -88,7 +89,7 @@ class S3PacketLoader: # pylint: disable=too-few-public-methods
sleep_interval
=
min
(
max_wait_time
,
MINIO_POLL_INTERVAL
)
time
.
sleep
(
sleep_interval
.
seconds
)
if
self
.
_list_objects_after
(
timestamp
):
if
next
(
self
.
_list_objects_after
(
timestamp
)
,
False
)
:
logger
.
info
(
"
wait_for_packets: Requested timestamp appeared after waiting %s
"
,
datetime
.
now
(
tz
=
timestamp
.
tzinfo
)
-
start_time
,
...
...
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