|
@@ -1,3 +1,4 @@
|
|
|
|
+import socket
|
|
import time
|
|
import time
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from apscheduler.schedulers.background import BackgroundScheduler
|
|
from django_apscheduler.jobstores import DjangoJobStore
|
|
from django_apscheduler.jobstores import DjangoJobStore
|
|
@@ -8,12 +9,18 @@ import pytz
|
|
|
|
|
|
class ApschedulerObject:
|
|
class ApschedulerObject:
|
|
def __init__(self, timezone_offset=0.00):
|
|
def __init__(self, timezone_offset=0.00):
|
|
- # 计算时区偏移量(以分钟为单位)
|
|
|
|
- timezone_offset_minutes = int(timezone_offset * 60)
|
|
|
|
- timezone = pytz.FixedOffset(timezone_offset_minutes)
|
|
|
|
- self.scheduler = BackgroundScheduler(timezone=timezone)
|
|
|
|
- self.scheduler.add_jobstore(DjangoJobStore(), 'default')
|
|
|
|
- self.scheduler.start()
|
|
|
|
|
|
+ try:
|
|
|
|
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
+ sock.bind(('127.0.0.1', 12345))
|
|
|
|
+ except socket.error:
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ # 计算时区偏移量(以分钟为单位)
|
|
|
|
+ timezone_offset_minutes = int(timezone_offset * 60)
|
|
|
|
+ timezone = pytz.FixedOffset(timezone_offset_minutes)
|
|
|
|
+ self.scheduler = BackgroundScheduler(timezone=timezone)
|
|
|
|
+ self.scheduler.add_jobstore(DjangoJobStore(), 'default')
|
|
|
|
+ self.scheduler.start()
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
def auto_hello(x): # 任务
|
|
def auto_hello(x): # 任务
|