-
Notifications
You must be signed in to change notification settings - Fork 7
/
Timer.py
51 lines (34 loc) · 1.1 KB
/
Timer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- mode: python; indent-tabs-mode: nil; -*- coding: utf-8 -*-
"""
Timer.py
Copyright 2010-2013 by Marcello Perathoner
Distributable under the GNU General Public License Version 3 or newer.
A cron-like process that runs at fixed intervals.
Usage:
import Timer
cherrypy.process.plugins.Timer = TimerPlugin
"""
from __future__ import unicode_literals
import cherrypy
import BaseSearcher
class TimerPlugin (cherrypy.process.plugins.Monitor):
""" Plugin to start the timer thread.
We cannot start any threads before daemonizing,
so we must start the timer thread by this plugin.
"""
def __init__ (self, bus):
# interval in seconds
frequency = 300
super (TimerPlugin, self).__init__ (bus, self.tick, frequency)
self.name = 'timer'
def start (self):
super (TimerPlugin, self).start ()
self.tick ()
start.priority = 80
def tick (self):
""" Do things here. """
try:
BaseSearcher.books_in_archive = BaseSearcher.sql_get ('select count (*) from books')
except:
pass