Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/routers/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ def sync_dashboard():
if response.status_code != status.HTTP_200_OK:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Error syncing processor with dashbord"
detail="Error syncing processor with dashboard"
)
return response.json()
6 changes: 3 additions & 3 deletions api/routers/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ async def delete_camera(camera_id: str, reboot_processor: Optional[bool] = True)

# Delete all directories related to a given camera.
camera_screenshot_directory = os.path.join(os.environ.get("ScreenshotsDirectory"), camera_id)
shutil.rmtree(camera_screenshot_directory)
shutil.rmtree(camera_screenshot_directory, ignore_errors=True)
source_directory = os.path.join(os.getenv("SourceLogDirectory"), camera_id)
shutil.rmtree(source_directory)
shutil.rmtree(source_directory, ignore_errors=True)
source_config_directory = os.path.join(os.getenv("SourceConfigDirectory"), camera_id)
shutil.rmtree(source_config_directory)
shutil.rmtree(source_config_directory, ignore_errors=True)

return handle_response(None, success, status.HTTP_204_NO_CONTENT)

Expand Down
33 changes: 23 additions & 10 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import humps
import os
import shutil
import time

from fastapi import status, HTTPException
from fastapi.encoders import jsonable_encoder
Expand All @@ -10,6 +11,8 @@

from .settings import Settings

MAX_PROCESSOR_RESTARTS = 5

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -41,16 +44,26 @@ def extract_config(config_type="all"):
def restart_processor():
from .queue_manager import QueueManager
logger.info("Restarting video processor...")
queue_manager = QueueManager()
queue_manager.cmd_queue.put(Commands.STOP_PROCESS_VIDEO)
stopped = queue_manager.result_queue.get()
if stopped:
queue_manager.cmd_queue.put(Commands.PROCESS_VIDEO_CFG)
started = queue_manager.result_queue.get()
if not started:
logger.info("Failed to restart video processor...")
return False
return True
restarts = 0
while True:
try:
queue_manager = QueueManager()
queue_manager.cmd_queue.put(Commands.STOP_PROCESS_VIDEO)
stopped = queue_manager.result_queue.get()
if stopped:
queue_manager.cmd_queue.put(Commands.PROCESS_VIDEO_CFG)
started = queue_manager.result_queue.get()
if not started:
logger.info("Failed to restart video processor...")
return False
return True
except:
restarts += 1
if restarts == MAX_PROCESSOR_RESTARTS:
# Exception raised when processor was restarted
return False
time.sleep(1)
logger.info("Unexpected error restarting the processor. Retrying...")


def update_config(config_dict, reboot_processor):
Expand Down