Skip to content

Commit

Permalink
Merge pull request #3 from cgDeepLearn/develop
Browse files Browse the repository at this point in the history
mgr-worker
  • Loading branch information
cgDeepLearn authored Sep 9, 2021
2 parents fc7f660 + 82aeadb commit 45be69c
Show file tree
Hide file tree
Showing 30 changed files with 1,034 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .dockerfiles/sbackend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /usr/app/sbackend

ENV TZ=Asia/Shanghai

ENV BACKEND_PORT=30001
ENV BACKEND_PORT=40001

EXPOSE $BACKEND_PORT

Expand Down
2 changes: 1 addition & 1 deletion .dockerfiles/smgr.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /usr/app/smgr

ENV TZ=Asia/Shanghai

ENV MGR_PORT=30002
ENV MGR_PORT=40002

EXPOSE $MGR_PORT

Expand Down
5 changes: 2 additions & 3 deletions .dockerfiles/sworker.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ WORKDIR /usr/app/sworker

ENV TZ=Asia/Shanghai

ENV WORKER_PORT=30001
ENV WORKER_PORT=40001

ENV WORKER_INDEX=1

EXPOSE $WORKER_PORT

CMD ["python3", "main.py", "sworker", "$WORKER_INDEX"]
CMD ["python3", "main.py", "sworker"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ A interface integrate with manager and worker running in backend docker
- [x] `docker` version: 20.10.5
- [x] `docker-compose` version 1.29.2
- [x] `python` version: 3.8.5
- [x] DBUtils==1.3.0
- [x] psycopg2==2.8.6
- [x] Flask==1.1.2
- [x] Flask-RESTful==0.3.8
- [x] APScheduler==3.7.0
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- redis-data:/data
- "/etc/localtime:/etc/localtime:ro"
command: --appendonly yes --requirepass ${REDIS_PASSWORD}
ports:
- "46379:6379"
networks:
- mynet

Expand All @@ -16,8 +18,11 @@ services:
image: postgres:12.5
volumes:
- postgres-data:/var/lib/postgresql/data
- "/etc/localtime:/etc/localtime:ro"
env_file:
- .envs/.local/.postgres
ports:
- "45432:5432"
networks:
- mynet

Expand All @@ -34,6 +39,8 @@ services:
env_file:
- .envs/.local/.postgres
- .envs/.local/.redis
ports:
- "40001:40001"
depends_on:
- sredis
- spostgres
Expand All @@ -52,8 +59,11 @@ services:
volumes:
- /var/log/smgr:/var/log/smgr
- "/etc/localtime:/etc/localtime:ro"
ports:
- "40002:40002"
depends_on:
- sredis
- spostgres
networks:
- mynet

Expand All @@ -71,6 +81,8 @@ services:
volumes:
- /var/log/sworker1:/var/log/sworker
- "/etc/localtime:/etc/localtime:ro"
expose:
- "40003"
depends_on:
- sredis
- smgr
Expand All @@ -91,6 +103,8 @@ services:
volumes:
- /var/log/sworker2:/var/log/sworker
- "/etc/localtime:/etc/localtime:ro"
expose:
- "40003"
depends_on:
- sredis
- smgr
Expand Down
55 changes: 55 additions & 0 deletions scripts/backend.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--update_time_func trigger
DROP FUNCTION IF EXISTS "public"."update_time_func"();
CREATE OR REPLACE FUNCTION "public"."update_time_func"()
RETURNS "pg_catalog"."trigger" AS $BODY$
begin
new.update_time = current_timestamp;
return new;
end
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

-----------
--- Table structure for t_task
------ -----
DROP TABLE IF EXISTS "t_task";
CREATE TABLE "t_task" (
"id" SERIAL NOT NULL PRIMARY KEY,
"name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"is_delete" bool NOT NULL DEFAULT false,
"create_by" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"create_time" timestamp(6) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"update_by" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"update_time" timestamp(6) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
)
;
-- ----------------------------
-- Triggers structure for table t_task
-- ----------------------------
CREATE TRIGGER "t_task_update" BEFORE UPDATE ON "t_task"
FOR EACH ROW
EXECUTE PROCEDURE "update_time_func"();


-----------
--- Table structure for t_task_detail
------ -----
DROP TABLE IF EXISTS "t_task_detail";
CREATE TABLE "t_task_detail" (
"id" SERIAL NOT NULL PRIMARY KEY,
"task_id" INTEGER NOT NULL,
"sub_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
"trigger" json NOT NULL default '{}',
"action" json NOT NULL default '{}',
"is_delete" bool NOT NULL DEFAULT false,
"create_time" timestamp(6) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"update_time" timestamp(6) without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
)
;
-- ----------------------------
-- Triggers structure for table t_task_detail
-- ----------------------------
CREATE TRIGGER "t_task_detail_update" BEFORE UPDATE ON "t_task_detail"
FOR EACH ROW
EXECUTE PROCEDURE "update_time_func"();
18 changes: 11 additions & 7 deletions src/sbackend/config/cfg.ini
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@

[Log:Setup]
# LOG_PATH = /var/log/sbackend/
LOG_PATH = ./
LOG_PATH = /var/log/sbackend/
;LOG_PATH = ./
MAX_SIZE = 5242880
BACKUP_COUNT = 10
LOG_FILENAME = sbackend

[Database:Setup]
POSTGRES_DATABASE = db_task
POSTGRES_USERNAME = postgres
POSTGRES_PASSWORD = postgres
POSTGRES_USER = postgres
;POSTGRES_PASSWORD = acb153
;POSTGRES_HOST = 172.24.4.56
;POSTGRES_PORT = 45432
POSTGRES_PASSWORD = acb153
POSTGRES_HOST = spostgres
POSTGRES_PORT = 5432

[Flask:Setup]
FLASK_PORT = 30001
FLASK_PORT = 40001
FLASK_IP = 0.0.0.0
FLASK_DEBUG = 0

[Redis:Setup]
;REDIS_HOST = s-redis
REDIS_HOST = localhost
REDIS_HOST = sredis
;REDIS_HOST = localhost
REDIS_PORT = 6379
REDIS_PWD = 12345
REDIS_DB = 12

[Services:Setup]
BACKEND_HOST = sbackend
MGR_HOST = smgr
MGR_PORT = 40002
WORKER_HOST = sworker
17 changes: 8 additions & 9 deletions src/sbackend/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from configparser import ConfigParser

LOG_SECTION_NAME = 'Log:Setup'
DATABASE_SECTION_NAME = 'DATABASE:Setup'
DATABASE_SECTION_NAME = 'Database:Setup'
FLASK_SECTION_NAME = 'Flask:Setup'
REDIS_SECTION_NAME = 'Redis:Setup'
SERVICES_SECTION_NAME = 'Services:Setup'
Expand Down Expand Up @@ -51,29 +51,27 @@ def get_db_cfg(self):
数据库配置
"""
_meta = {}
if env_config.get("POSTGRES_HOST"):
if env_config.get("POSTGRES_PASSWORD"):
# 环境变量有配置数据库信息,使用环境变量的配置否则使用程序的默认配置
_meta = env_config
elif self.cfgparser.has_section(DATABASE_SECTION_NAME):
_meta = dict(self.cfgparser.items(DATABASE_SECTION_NAME))

pg_db_host = _meta.get('POSTGRES_HOST', 'spostgres')
pg_db_port = int(_meta.get('POSTGRES_PORT', '5432'))
pg_db_username = _meta.get('POSTGRES_USERNAME', '')
pg_db_username = _meta.get('POSTGRES_USER', '')
pg_db_password = _meta.get('POSTGRES_PASSWORD', '')
pg_db_database = _meta.get('POSTGRES_DATABASE', 'db_task')

return pg_db_database, pg_db_username, pg_db_password, pg_db_host, pg_db_port

def get_redis_cfg(self):
"""redis配置"""
_meta = {}
if env_config.get("REDIS_HOST"):
if env_config.get("REDIS_PASSWORD"):
# 环境变量有配置IOTDB数据库信息,使用环境变量的配置否则使用程序的默认配置
_meta = env_config
elif self.cfgparser.has_section(REDIS_SECTION_NAME):
_meta = dict(self.cfgparser.items(REDIS_SECTION_NAME))
redis_host = _meta.get('REDIS_HOST', 'None')
redis_host = _meta.get('REDIS_HOST', 'sredis')
redis_port = int(_meta.get('REDIS_PORT', '6379'))
redis_pwd = _meta.get('REDIS_PASSWORD', '12345')
redis_db = int(_meta.get('REDIS_DB', '12'))
Expand All @@ -95,15 +93,16 @@ def get_flask_cfg(self):
def get_services_cfg(self):
"""获取各服务的访问名字"""
_meta = {}
if env_config.get("BACKEND_HOST"):
if env_config.get("MGR_HOST"):
# 环境变量有配置各服务访问名的配置信息,使用环境变量的配置否则使用程序的默认配置
_meta = env_config
elif self.cfgparser.has_section(SERVICES_SECTION_NAME):
_meta = dict(self.cfgparser.items(SERVICES_SECTION_NAME))
backend_host = _meta.get("BACKEND_HOST", "sbackend") # 后端服务
mgr_host = _meta.get("MGR_HOST", "smgr") # smgr
mgr_port = int(_meta.get("MGR_PORT", "40002")) # mgr port
worker_host = _meta.get("WORKER_HOST", "sworker") # sworker
return backend_host, mgr_host, worker_host
return backend_host, mgr_host, mgr_port, worker_host


cfg = Config("config/cfg.ini")
Loading

0 comments on commit 45be69c

Please sign in to comment.