From 93c0c0f0c9c215cc7a9688119896dfcb0c84750e Mon Sep 17 00:00:00 2001 From: "tanglinchuanz@163.com" Date: Tue, 1 Mar 2022 11:23:21 +0800 Subject: [PATCH 1/3] crontab timer support --- Dockerfile | 2 ++ requirements.txt | 3 ++- wxcloudrun/settings.py | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 421e250..94bc312 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,3 +33,5 @@ CMD ["python3", "manage.py", "runserver", "0.0.0.0:80"] RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone \ && apk del tzdata + +RUN python3 manage.py crontab add \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2f1aaf4..774e439 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ PyJWT==2.3.0 PyMySQL==1.0.2 requests==2.27.1 urllib3==1.26.8 -pycryptodome==3.9.7 \ No newline at end of file +pycryptodome==3.9.7 +django_crontab \ No newline at end of file diff --git a/wxcloudrun/settings.py b/wxcloudrun/settings.py index ad3cbf1..f0ab93b 100644 --- a/wxcloudrun/settings.py +++ b/wxcloudrun/settings.py @@ -29,6 +29,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_crontab', 'wxcloudrun', 'wxBackendsapi' ] @@ -123,6 +124,9 @@ LOGGING = { }, # 过滤 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse', + }, }, # 定义具体处理日志的方式 'handlers': { @@ -166,7 +170,7 @@ LOGGING = { 'mail_admins': { 'level': 'ERROR', 'class': 'django.utils.log.AdminEmailHandler', - # 'filters': ['require_debug_false'], + 'filters': ['require_debug_false'], 'include_html': True, } }, @@ -187,6 +191,10 @@ LOGGING = { } } +CRONJOBS = [ + ('*/1 * * * *', 'wxBackendsapi.views.timer', ['',''], {}, '>> /var/log/crontab.log') +] + # Internationalization # https://docs.djangoproject.com/en/3.2/topics/i18n/ -- Gitee From c99e7726b895452b5832bdcd7614db486e9c58e5 Mon Sep 17 00:00:00 2001 From: "tanglinchuanz@163.com" Date: Tue, 1 Mar 2022 14:30:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?crontab=20=E6=94=B9=E4=B8=BA=E6=AF=8F?= =?UTF-8?q?=E5=B0=8F=E6=97=B630=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wxcloudrun/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wxcloudrun/settings.py b/wxcloudrun/settings.py index f0ab93b..3c7c968 100644 --- a/wxcloudrun/settings.py +++ b/wxcloudrun/settings.py @@ -192,7 +192,7 @@ LOGGING = { } CRONJOBS = [ - ('*/1 * * * *', 'wxBackendsapi.views.timer', ['',''], {}, '>> /var/log/crontab.log') + ('30 * * * *', 'wxBackendsapi.views.timer', ['',''], {}, '>> /var/log/crontab.log') ] # Internationalization -- Gitee From 17e57ea836d34ceff33f4305222ffcd234012726 Mon Sep 17 00:00:00 2001 From: "tanglinchuanz@163.com" Date: Wed, 2 Mar 2022 12:52:41 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0isShow=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0014_ddlinfo_isshow.py | 18 ++++++++++++++++++ wxBackendsapi/models.py | 1 + wxcloudrun/settings.py | 4 ++-- wxcloudrun/views.py | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 wxBackendsapi/migrations/0014_ddlinfo_isshow.py diff --git a/wxBackendsapi/migrations/0014_ddlinfo_isshow.py b/wxBackendsapi/migrations/0014_ddlinfo_isshow.py new file mode 100644 index 0000000..9d6df1e --- /dev/null +++ b/wxBackendsapi/migrations/0014_ddlinfo_isshow.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.8 on 2022-03-01 15:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wxBackendsapi', '0013_ddlinfo_modulename'), + ] + + operations = [ + migrations.AddField( + model_name='ddlinfo', + name='isShow', + field=models.BooleanField(default=True, verbose_name='isShow'), + ), + ] diff --git a/wxBackendsapi/models.py b/wxBackendsapi/models.py index a07b658..d5444fc 100644 --- a/wxBackendsapi/models.py +++ b/wxBackendsapi/models.py @@ -27,6 +27,7 @@ class DDLInfo(models.Model): # courseState = models.BooleanField("Course State", default=True) assState = models.BooleanField("Assignment State", default=True) isSubmit = models.BooleanField("isSubmit", default=False) + isShow = models.BooleanField("isShow", default=True) moduleName = models.CharField("Module Name", max_length=100, default="") class Meta: verbose_name = "DDLInfo" diff --git a/wxcloudrun/settings.py b/wxcloudrun/settings.py index 3c7c968..db6e56a 100644 --- a/wxcloudrun/settings.py +++ b/wxcloudrun/settings.py @@ -72,8 +72,8 @@ DATABASES = { 'ENGINE': 'django.db.backends.mysql', 'NAME': os.environ.get("MYSQL_DATABASE", 'UIC_Circles'), 'USER': os.environ.get("MYSQL_USERNAME", 'root'), - 'HOST': os.environ.get("MYSQL_ADDRESS", "192.168.10.113:3306").split(':')[0], - 'PORT': os.environ.get("MYSQL_ADDRESS", "192.168.10.113:3306").split(':')[1], + 'HOST': os.environ.get("MYSQL_ADDRESS", "127.0.0.1:3306").split(':')[0], + 'PORT': os.environ.get("MYSQL_ADDRESS", "127.0.0.1:3306").split(':')[1], 'PASSWORD': os.environ.get("MYSQL_PASSWORD", '12345678'), 'OPTIONS': {'charset': 'utf8mb4'}, } diff --git a/wxcloudrun/views.py b/wxcloudrun/views.py index 7ebf976..f226f4b 100644 --- a/wxcloudrun/views.py +++ b/wxcloudrun/views.py @@ -62,7 +62,7 @@ def login(request, _): weixinRsp = json.loads(weixinRsp) # skip weixin auth - # weixinRsp = {'openid': 'testid'} + weixinRsp = {'openid': 'testid'} if 'errcode' in weixinRsp or 'openid' not in weixinRsp: # weixin authorize fail -- Gitee