Repository: openfun/marsha

Issue:
check_live_state pop from empty list
## Bug Report

**Problematic Behavior**

The management command check_live_state has a recurring error, it tries to pop a value from an empty list. This list comes from cloudwatch service : https://github.com/openfun/marsha/blob/29e1f78ed6e288f7bba3c198bb7b7179e7af4fe0/src/backend/marsha/core/management/commands/check_live_state.py#L100

**Expected behavior/code**

This error seems to occur when a live has no activity anymore. We try to compare alerts set and the clear to determine if they are still active.


**Steps to Reproduce**
1. Start a webinar
2. Once started, stop all activity
3. Run the management command `check_live_state`
4. And then the bug happens!




Discussion:

Resolving patch:
diff --git a/src/backend/marsha/core/management/commands/check_live_state.py b/src/backend/marsha/core/management/commands/check_live_state.py
--- a/src/backend/marsha/core/management/commands/check_live_state.py
+++ b/src/backend/marsha/core/management/commands/check_live_state.py
@@ -67,7 +67,7 @@ def handle(self, *args, **options):
             live_info = video.live_info
             logs = logs_client.filter_log_events(
                 logGroupName=live_info["cloudwatch"]["logGroupName"],
-                startTime=int(int(video.live_info.get("started_at")) * 1000),
+                startTime=int((int(video.live_info.get("started_at")) - 60) * 1000),
                 filterPattern=(
                     "{"
                     '($.detail-type = "MediaLive Channel Alert") && '


Test patch:
diff --git a/src/backend/marsha/core/tests/management_commands/test_check_live_state.py b/src/backend/marsha/core/tests/management_commands/test_check_live_state.py
--- a/src/backend/marsha/core/tests/management_commands/test_check_live_state.py
+++ b/src/backend/marsha/core/tests/management_commands/test_check_live_state.py
@@ -53,7 +53,7 @@ def test_check_live_state_live_running_not_ended(self):
                 "filter_log_events",
                 expected_params={
                     "logGroupName": "/aws/lambda/dev-test-marsha-medialive",
-                    "startTime": 1598313600000,
+                    "startTime": 1598313540000,
                     "filterPattern": (
                         "{"
                         '($.detail-type = "MediaLive Channel Alert") && '
@@ -151,7 +151,7 @@ def test_check_live_state_running_ended_not_expired(self):
                 "filter_log_events",
                 expected_params={
                     "logGroupName": "/aws/lambda/dev-test-marsha-medialive",
-                    "startTime": 1598313600000,
+                    "startTime": 1598313540000,
                     "filterPattern": (
                         "{"
                         '($.detail-type = "MediaLive Channel Alert") && '
@@ -236,7 +236,7 @@ def test_check_live_state_running_ended_and_expired(self):
                 "filter_log_events",
                 expected_params={
                     "logGroupName": "/aws/lambda/dev-test-marsha-medialive",
-                    "startTime": 1598313600000,
+                    "startTime": 1598313540000,
                     "filterPattern": (
                         "{"
                         '($.detail-type = "MediaLive Channel Alert") && '