Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
TFS
controller
Commits
ea35c20d
Commit
ea35c20d
authored
8 months ago
by
Javier Diaz
Browse files
Options
Downloads
Patches
Plain Diff
Async Implementation, Batches
parent
113a54dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!294
Release TeraFlowSDN 4.0
,
!259
Resolve "(CTTC) Replace DLT Gateway functionality with an opensource and Hyper Ledger v2.4+ compliant version"
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/interdomain/service/topology_abstractor/DltRecorder.py
+40
-25
40 additions, 25 deletions
src/interdomain/service/topology_abstractor/DltRecorder.py
with
40 additions
and
25 deletions
src/interdomain/service/topology_abstractor/DltRecorder.py
+
40
−
25
View file @
ea35c20d
...
@@ -65,40 +65,55 @@ class DLTRecorder(threading.Thread):
...
@@ -65,40 +65,55 @@ class DLTRecorder(threading.Thread):
create_context
(
self
.
context_client
,
DEFAULT_CONTEXT_NAME
)
create_context
(
self
.
context_client
,
DEFAULT_CONTEXT_NAME
)
#self.create_topologies()
#self.create_topologies()
self
.
context_event_collector
.
start
()
self
.
context_event_collector
.
start
()
tasks
=
[]
batch_timeout
=
1
# Time in seconds to wait before processing whatever tasks are available
batch_timeout
=
1
# Time in seconds to wait before processing whatever tasks are available
last_task_time
=
time
.
time
()
last_task_time
=
time
.
time
()
while
not
self
.
terminate
.
is_set
():
while
not
self
.
terminate
.
is_set
():
event
=
self
.
context_event_collector
.
get_event
(
timeout
=
0.1
)
event
=
self
.
context_event_collector
.
get_event
(
timeout
=
0.1
)
if
event
:
if
event
:
LOGGER
.
info
(
'
Processing Event({:s})...
'
.
format
(
grpc_message_to_json_string
(
event
)))
LOGGER
.
info
(
'
Received Event({:s})...
'
.
format
(
grpc_message_to_json_string
(
event
)))
task
=
asyncio
.
create_task
(
self
.
update_record
(
event
))
tasks
.
append
(
task
)
# Prioritize the event based on its type
LOGGER
.
debug
(
'
Task for event scheduled.
'
)
if
event
.
event
.
event_type
==
1
:
# CREATE
await
self
.
create_event_queue
.
put
(
event
)
# Update the last task time since we've added a new task
elif
event
.
event
.
event_type
==
2
:
# UPDATE
last_task_time
=
time
.
time
()
await
self
.
update_event_queue
.
put
(
event
)
elif
event
.
event
.
event_type
==
3
:
# REMOVE
# Check if it's time to process the tasks or if we have enough tasks
await
self
.
remove_event_queue
.
put
(
event
)
if
tasks
and
(
len
(
tasks
)
>=
10
or
(
time
.
time
()
-
last_task_time
>=
batch_timeout
)):
try
:
# Check if it's time to process the tasks or if we have enough tasks
await
asyncio
.
gather
(
*
tasks
)
current_time
=
time
.
time
()
except
Exception
as
e
:
if
current_time
-
last_task_time
>=
batch_timeout
:
LOGGER
.
error
(
f
"
Error while processing tasks:
{
e
}
"
)
await
self
.
process_events
()
finally
:
last_task_time
=
current_time
# Reset the timer after processing
tasks
=
[]
# Clear the list after processing
self
.
context_event_collector
.
stop
()
# Process any remaining tasks when stopping
self
.
context_client
.
close
()
async
def
process_events
(
self
):
# Process CREATE events first
await
self
.
process_queue
(
self
.
create_event_queue
)
# Then process UPDATE events
await
self
.
process_queue
(
self
.
update_event_queue
)
# Finally, process REMOVE events
await
self
.
process_queue
(
self
.
remove_event_queue
)
async
def
process_queue
(
self
,
queue
:
asyncio
.
Queue
):
tasks
=
[]
while
not
queue
.
empty
():
event
=
await
queue
.
get
()
LOGGER
.
info
(
'
Processing Event({:s}) from queue...
'
.
format
(
grpc_message_to_json_string
(
event
)))
task
=
asyncio
.
create_task
(
self
.
update_record
(
event
))
tasks
.
append
(
task
)
# Execute tasks concurrently
if
tasks
:
if
tasks
:
try
:
try
:
await
asyncio
.
gather
(
*
tasks
)
await
asyncio
.
gather
(
*
tasks
)
except
Exception
as
e
:
except
Exception
as
e
:
LOGGER
.
error
(
f
"
Error while processing remaining tasks:
{
e
}
"
)
LOGGER
.
error
(
f
"
Error while processing tasks:
{
e
}
"
)
self
.
context_event_collector
.
stop
()
self
.
context_client
.
close
()
async
def
update_record
(
self
,
event
:
EventTypes
)
->
None
:
async
def
update_record
(
self
,
event
:
EventTypes
)
->
None
:
dlt_record_sender
=
DltRecordSender
(
self
.
context_client
)
dlt_record_sender
=
DltRecordSender
(
self
.
context_client
)
...
...
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