|
@@ -75,7 +75,6 @@ class EventService(VTNService):
|
|
|
"""
|
|
|
The VEN informs us that they created an EiEvent.
|
|
|
"""
|
|
|
- loop = asyncio.get_event_loop()
|
|
|
ven_id = payload['ven_id']
|
|
|
if self.polling_method == 'internal':
|
|
|
for event_response in payload['event_responses']:
|
|
@@ -91,26 +90,7 @@ class EventService(VTNService):
|
|
|
result = await result
|
|
|
if opt_type == 'optIn':
|
|
|
self.running_events[event_id] = (event, callback)
|
|
|
- now = datetime.now(timezone.utc)
|
|
|
- active_period = event.active_period
|
|
|
- # Schedule status update to 'near' if applicable
|
|
|
- if active_period.ramp_up_period is not None and event.event_descriptor.event_status == 'far':
|
|
|
- ramp_up_start_delay = (active_period.dtstart - active_period.ramp_up_period) - now
|
|
|
- update_coro = partial(self._update_event_status, ven_id, event, 'near')
|
|
|
- loop.create_task(utils.delayed_call(func=update_coro, delay=ramp_up_start_delay),
|
|
|
- name=f'DelayedCall-{utils.generate_id()}')
|
|
|
- # Schedule status update to 'active'
|
|
|
- if event.event_descriptor.event_status in ('near', 'far'):
|
|
|
- active_start_delay = active_period.dtstart - now
|
|
|
- update_coro = partial(self._update_event_status, ven_id, event, 'active')
|
|
|
- loop.create_task(utils.delayed_call(func=update_coro, delay=active_start_delay),
|
|
|
- name=f'DelayedCall-{utils.generate_id()}')
|
|
|
- # Schedule status update to 'completed'
|
|
|
- if event.event_descriptor.event_status in ('near', 'far', 'active'):
|
|
|
- active_end_delay = active_period.dtstart + active_period.duration - now
|
|
|
- update_coro = partial(self._update_event_status, ven_id, event, 'completed')
|
|
|
- loop.create_task(utils.delayed_call(func=update_coro, delay=active_end_delay),
|
|
|
- name=f'DelayedCall-{utils.generate_id()}')
|
|
|
+ self.schedule_event_updates(ven_id, event)
|
|
|
elif event_response['event_id'] in self.running_events:
|
|
|
event, callback = self.running_events.pop(event_id)
|
|
|
result = callback(ven_id=ven_id, event_id=event_id, opt_type=opt_type)
|
|
@@ -140,3 +120,29 @@ class EventService(VTNService):
|
|
|
if event_status == enums.EVENT_STATUS.CANCELLED:
|
|
|
event.event_descriptor.modification_number += 1
|
|
|
self.message_queues[ven_id].append(event)
|
|
|
+
|
|
|
+ def schedule_event_updates(self, ven_id, event):
|
|
|
+ """
|
|
|
+ Schedules the event updates.
|
|
|
+ """
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
+ now = datetime.now(timezone.utc)
|
|
|
+ active_period = event.active_period
|
|
|
+ # Schedule status update to 'near' if applicable
|
|
|
+ if active_period.ramp_up_period is not None and event.event_descriptor.event_status == 'far':
|
|
|
+ ramp_up_start_delay = (active_period.dtstart - active_period.ramp_up_period) - now
|
|
|
+ update_coro = partial(self._update_event_status, ven_id, event, 'near')
|
|
|
+ loop.create_task(utils.delayed_call(func=update_coro, delay=ramp_up_start_delay),
|
|
|
+ name=f'DelayedCall-EventStatusToNear-{event.event_descriptor.event_id}')
|
|
|
+ # Schedule status update to 'active'
|
|
|
+ if event.event_descriptor.event_status in ('near', 'far'):
|
|
|
+ active_start_delay = active_period.dtstart - now
|
|
|
+ update_coro = partial(self._update_event_status, ven_id, event, 'active')
|
|
|
+ loop.create_task(utils.delayed_call(func=update_coro, delay=active_start_delay),
|
|
|
+ name=f'DelayedCall-EventStatusToActive-{event.event_descriptor.event_id}')
|
|
|
+ # Schedule status update to 'completed'
|
|
|
+ if event.event_descriptor.event_status in ('near', 'far', 'active'):
|
|
|
+ active_end_delay = active_period.dtstart + active_period.duration - now
|
|
|
+ update_coro = partial(self._update_event_status, ven_id, event, 'completed')
|
|
|
+ loop.create_task(utils.delayed_call(func=update_coro, delay=active_end_delay),
|
|
|
+ name=f'DelayedCall-EventStatusToCompleted-{event.event_descriptor.event_id}')
|