Skip to content

Commit

Permalink
docs(Redis Workers): Reimplementation
Browse files Browse the repository at this point in the history
Reimplementing redis server worker management using the multiprocessing
library. Not tested and not final.
  • Loading branch information
mibs510 committed Jun 19, 2023
1 parent 1f0d805 commit 9ceb4e7
Show file tree
Hide file tree
Showing 9 changed files with 1,587 additions and 29 deletions.
17 changes: 12 additions & 5 deletions apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
import platform
import subprocess
from datetime import datetime
Expand Down Expand Up @@ -79,11 +80,17 @@ def initialize_settings():
# Start redis workers on Linux only
if platform.system() == "Linux":
from apps.alpr.models.settings import CameraSettings
camera_workers = len(CameraSettings.get_all_enabled())
workers_cmd = subprocess.run(["./workers.py", "-c", camera_workers, "-g", camera_workers])
print("workers_cmd.returncode = {}".format(workers_cmd.returncode))
print("workers_cmd.stdout = {}".format(workers_cmd.stdout))
print("workers_cmd.stderr = {}".format(workers_cmd.stderr))
camera_workers = CameraSettings.get_all_enabled_count()
workers_cmd = subprocess.Popen(["python3", os.path.dirname(os.path.realpath(__file__)) +
"/workers.py", "-c", str(camera_workers), "-g", str(camera_workers)],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output, error = workers_cmd.communicate()
if workers_cmd.returncode != 0:
app.logger.info("workers_cmd.returncode = {}".format(workers_cmd.returncode))
app.logger.info("workers_cmd.errorcode = {}".format(str(error, 'utf-8')))

app.logger.info("workers_cmd.stdout = {}".format(workers_cmd.stdout))
app.logger.info("workers_cmd.stderr = {}".format(workers_cmd.stderr))


def create_app(config) -> Flask:
Expand Down
16 changes: 11 additions & 5 deletions apps/alpr/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class AccountStatus(enum.Enum):
ACTIVATED = 1


class AccountVerified(enum.Enum):
NON_VERIFIED = 0
VERIFIED = 1


class ChartType(enum.Enum):
ALERT_CHART = "alert-chart"
PLATES_CAPTURED_CHART = "plates-captured-chart"
Expand All @@ -18,16 +23,17 @@ class DataType(enum.Enum):
VEHICLE = "vehicle"


class MultiProcessCommand(enum.Enum):
START_WORKER = "start-worker"
STOP_WORKER = "stop-worker"
CLOSE_CONNECTION = "close"


class UserRole(enum.Enum):
ADMIN = "ADMIN"
REGULAR = "NONADMIN"


class AccountVerified(enum.Enum):
NON_VERIFIED = 0
VERIFIED = 1


class WorkerType(enum.Enum):
# worker type = queue name
Camera = 'cameras'
Expand Down
4 changes: 4 additions & 0 deletions apps/alpr/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def filter_by_id(cls, _id: int) -> "CameraSettings":
def get_all_enabled(cls) -> []:
return cls.query.filter_by(enable=True)

@classmethod
def get_all_enabled_count(cls) -> int:
return cls.query.filter_by(enable=True).count()

@classmethod
def get_camera_label(cls, _camera_id: int) -> "CameraSettings":
camera = cls.query.filter_by(camera_id=_camera_id).first()
Expand Down
Loading

0 comments on commit 9ceb4e7

Please sign in to comment.