Skip to content

Commit

Permalink
feat: build schedule events exclusively in playout (#2946)
Browse files Browse the repository at this point in the history
### Description

Build and use the schedule events only in playout, the events generated
by legacy are not used anymore.

This ensure that we don't have to maintain 2 different implementation in
2 different languages. We still need the php function to run to make
sure the side effects of this function are executed (filling the
schedule in the DB).
  • Loading branch information
jooola committed Apr 27, 2024
1 parent c02502a commit 40b4fc7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
6 changes: 4 additions & 2 deletions legacy/application/controllers/PreferenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ public function streamSettingAction()
if ($changeRGenabled || $changeRGmodifier) {
Application_Model_Preference::SetEnableReplayGain($values['enableReplayGain']);
Application_Model_Preference::setReplayGainModifier($values['replayGainModifier']);
$md = ['schedule' => Application_Model_Schedule::getSchedule()];
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', $md);
// The side effects of this function are still required to fill the schedule, we
// don't use the returned schedule.
Application_Model_Schedule::getSchedule();
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', []);
// Application_Model_RabbitMq::PushSchedule();
}

Expand Down
6 changes: 4 additions & 2 deletions legacy/application/controllers/plugins/RabbitMqPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ class RabbitMqPlugin extends Zend_Controller_Plugin_Abstract
public function dispatchLoopShutdown()
{
if (Application_Model_RabbitMq::$doPush) {
$md = ['schedule' => Application_Model_Schedule::getSchedule()];
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', $md);
// The side effects of this function are still required to fill the schedule, we
// don't use the returned schedule.
Application_Model_Schedule::getSchedule();
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', []);
}

if (memory_get_peak_usage() > 30 * 2 ** 20) {
Expand Down
6 changes: 4 additions & 2 deletions legacy/application/models/tests/populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ function createTestShow($showNumber, $showTime, $duration = '1:00')
}

if (Application_Model_RabbitMq::$doPush) {
$md = ['schedule' => Application_Model_Schedule::getSchedule()];
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', $md);
// The side effects of this function are still required to fill the schedule, we
// don't use the returned schedule.
Application_Model_Schedule::getSchedule();
Application_Model_RabbitMq::SendMessageToPypo('update_schedule', []);
}
4 changes: 2 additions & 2 deletions playout/libretime_playout/player/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ..liquidsoap.models import Info, MessageFormatKind, StreamPreferences, StreamState
from .events import Events, FileEvent, FileEvents
from .liquidsoap import Liquidsoap
from .schedule import get_schedule, receive_schedule
from .schedule import get_schedule

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,7 +70,7 @@ def handle_message(self, message: Dict[str, Any]) -> None:
logger.debug("handling event %s: %s", command, message)

if command == "update_schedule":
self.schedule_data = receive_schedule(message["schedule"]["media"])
self.schedule_data = get_schedule(self.api_client)
self.process_schedule(self.schedule_data)
elif command == "reset_liquidsoap_bootstrap":
self.set_bootstrap_variables()
Expand Down
10 changes: 0 additions & 10 deletions playout/libretime_playout/player/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
WebStreamEvent,
datetime_to_event_key,
event_isoparse,
parse_any_event,
)


Expand Down Expand Up @@ -213,12 +212,3 @@ def generate_webstream_events(
show_name=show["name"],
)
insert_event(events, schedule_end_event_key, stream_output_end_event)


def receive_schedule(schedule: Dict[str, dict]) -> Events:
events: Dict[str, AnyEvent] = {}

for event_key, event in schedule.items():
events[event_key] = parse_any_event(event)

return events

0 comments on commit 40b4fc7

Please sign in to comment.