qiaofeng1227 2 anni fa
parent
commit
4b94da339b
2 ha cambiato i file con 9 aggiunte e 8 eliminazioni
  1. 1 1
      appmanage/Dockerfile
  2. 8 7
      appmanage/api/service/manage.py

+ 1 - 1
appmanage/Dockerfile

@@ -10,7 +10,7 @@ COPY static ./static
 COPY requirements.txt main.py  ./
 COPY requirements.txt main.py  ./
 RUN apt update
 RUN apt update
 
 
-# Install supervisords
+# Install supervisord
 RUN apt install -y supervisor
 RUN apt install -y supervisor
 COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
 COPY config/cmd.sh /cmd.sh
 COPY config/cmd.sh /cmd.sh

+ 8 - 7
appmanage/api/service/manage.py

@@ -25,7 +25,7 @@ from apscheduler.schedulers.background import BackgroundScheduler
 from apscheduler.triggers.date import DateTrigger
 from apscheduler.triggers.date import DateTrigger
 from apscheduler.triggers.cron import CronTrigger
 from apscheduler.triggers.cron import CronTrigger
 from apscheduler.triggers.interval import IntervalTrigger
 from apscheduler.triggers.interval import IntervalTrigger
-
+from apscheduler.events import EVENT_SCHEDULER_PAUSED, EVENT_SCHEDULER_RESUMED,EVENT_SCHEDULER_STARTED,EVENT_SCHEDULER_SHUTDOWN
 
 
 # 指定 Redis 容器的主机名和端口
 # 指定 Redis 容器的主机名和端口
 redis_conn = Redis(host='websoft9-redis', port=6379)
 redis_conn = Redis(host='websoft9-redis', port=6379)
@@ -41,6 +41,9 @@ def test():
     shell_execute.execute_command_output_all("echo 1111 >> /tmp/test1")
     shell_execute.execute_command_output_all("echo 1111 >> /tmp/test1")
 
 
 scheduler = BackgroundScheduler()
 scheduler = BackgroundScheduler()
+scheduler.add_job(auto_update, 'cron', second=1)
+scheduler.add_job(test, 'cron', second=1)
+scheduler.start()
 
 
 # 获取github文件内容
 # 获取github文件内容
 def get_github_content(repo, path):
 def get_github_content(repo, path):
@@ -56,18 +59,16 @@ def AppAutoUpdate(auto_update):
     myLogger.info_logger(scheduler.state)
     myLogger.info_logger(scheduler.state)
     myLogger.info_logger(scheduler.get_jobs())
     myLogger.info_logger(scheduler.get_jobs())
     if auto_update:
     if auto_update:
-        if scheduler.state == 1 or scheduler.state == "1":
+        if scheduler.state == EVENT_SCHEDULER_RESUMED or scheduler.state == EVENT_SCHEDULER_STARTED:
             raise CommandException(const.ERROR_CLIENT_PARAM_REPEAT,"auto_update already in running state", "auto_update already in running state")
             raise CommandException(const.ERROR_CLIENT_PARAM_REPEAT,"auto_update already in running state", "auto_update already in running state")
         else:
         else:
-            scheduler.add_job(auto_update, 'cron', second=1)
-            scheduler.add_job(test, 'cron', second=1)
-            scheduler.start()  
+            scheduler.resume()
             return "软件商店自动更新已经开启"
             return "软件商店自动更新已经开启"
     else:
     else:
-        if scheduler.state == 0 or scheduler.state == "0":
+        if scheduler.state == EVENT_SCHEDULER_PAUSED:
             raise CommandException(const.ERROR_CLIENT_PARAM_REPEAT,"auto_update already in closed state", "auto_update already in closed state")
             raise CommandException(const.ERROR_CLIENT_PARAM_REPEAT,"auto_update already in closed state", "auto_update already in closed state")
         else:
         else:
-            scheduler.shutdown()
+            scheduler.pause()
             return "软件商店自动更新已经关闭"
             return "软件商店自动更新已经关闭"
 
 
 # 更新软件商店
 # 更新软件商店