|
|
@@ -1,35 +1,37 @@
|
|
1
|
|
-from apscheduler.jobstores.base import JobLookupError
|
|
2
|
|
-from apscheduler.schedulers.background import BackgroundScheduler
|
|
3
|
|
-import time
|
|
4
|
|
-
|
|
5
|
|
-class SchedulerTest:
|
|
6
|
|
- def __init__(self):
|
|
7
|
|
- self.sched = BackgroundScheduler()
|
|
8
|
|
- self.sched.start()
|
|
9
|
|
- self.job_id = ''
|
|
10
|
|
-
|
|
11
|
|
- def __del__(self):
|
|
12
|
|
- print("__del__ call")
|
|
13
|
|
- self.shutdown()
|
|
14
|
|
-
|
|
15
|
|
- def shutdown(self):
|
|
16
|
|
- self.sched.shutdown()
|
|
17
|
|
-
|
|
18
|
|
- def kill_scheduler(self, job_id):
|
|
19
|
|
- try:
|
|
20
|
|
- self.sched.remove_job(job_id)
|
|
21
|
|
- except JobLookupError as err:
|
|
22
|
|
- print("fail to stop Scheduler: {err}".format(err=err))
|
|
23
|
|
- return
|
|
24
|
|
-
|
|
25
|
|
- def hello(self, type, job_id):
|
|
26
|
|
- print("%s Scheduler process_id[%s] : %d" % (type, job_id, time.localtime().tm_sec))
|
|
27
|
|
-
|
|
28
|
|
- def scheduler(self, type, job_id):
|
|
29
|
|
- print("{type} Scheduler Start".format(type=type))
|
|
30
|
|
- if type == 'interval':
|
|
31
|
|
- self.sched.add_job(self.hello, type, seconds=10, id=job_id, args=(type, job_id))
|
|
32
|
|
- elif type == 'cron':
|
|
33
|
|
- self.sched.add_job(self.hello, type, day_of_week='mon-sun',
|
|
34
|
|
- hour='0-23', second='*/1',
|
|
35
|
|
- id=job_id, args=(type, job_id))
|
|
|
1
|
+from apscheduler.jobstores.base import JobLookupError
|
|
|
2
|
+from apscheduler.schedulers.background import BackgroundScheduler
|
|
|
3
|
+import time
|
|
|
4
|
+
|
|
|
5
|
+class SchedulerTest:
|
|
|
6
|
+ def __init__(self):
|
|
|
7
|
+ self.sched = BackgroundScheduler()
|
|
|
8
|
+ self.job_id = ''
|
|
|
9
|
+
|
|
|
10
|
+ def __del__(self):
|
|
|
11
|
+ print("__del__ call")
|
|
|
12
|
+ self.shutdown()
|
|
|
13
|
+
|
|
|
14
|
+ def start(self):
|
|
|
15
|
+ self.sched.start()
|
|
|
16
|
+
|
|
|
17
|
+ def shutdown(self):
|
|
|
18
|
+ self.sched.shutdown()
|
|
|
19
|
+
|
|
|
20
|
+ def kill_scheduler(self, job_id):
|
|
|
21
|
+ try:
|
|
|
22
|
+ self.sched.remove_job(job_id)
|
|
|
23
|
+ except JobLookupError as err:
|
|
|
24
|
+ print("fail to stop Scheduler: {err}".format(err=err))
|
|
|
25
|
+ return
|
|
|
26
|
+
|
|
|
27
|
+ def hello(self, type, job_id):
|
|
|
28
|
+ print("%s Scheduler process_id[%s] : %d" % (type, job_id, time.localtime().tm_sec))
|
|
|
29
|
+
|
|
|
30
|
+ def scheduler(self, type, job_id):
|
|
|
31
|
+ print("{type} Scheduler Start".format(type=type))
|
|
|
32
|
+ if type == 'interval':
|
|
|
33
|
+ self.sched.add_job(self.hello, type, seconds=10, id=job_id, args=(type, job_id))
|
|
|
34
|
+ elif type == 'cron':
|
|
|
35
|
+ self.sched.add_job(self.hello, type, day_of_week='mon-sun',
|
|
|
36
|
+ hour='0-23', second='*/1',
|
|
|
37
|
+ id=job_id, args=(type, job_id))
|