我注意到我的Firebase管理员事件侦听器每小时都会触发一次,即使数据库中没有任何更改也是如此。我整理了一个小型测试程序进行验证,发现这些更新是在设置初始侦听器后约60分钟每小时自动进行一次。
这是故意的吗?如果是这样,如何禁用此行为?
这是测试程序(我已经删除了一些* SENSITIVE VALUES *):
# Firebase modules
import os
import datetime
import firebase_admin
from firebase_admin import db
from firebase_admin import credentials
# Init Firebase.
dir_path = os.path.dirname(os.path.realpath(__file__))
cred = credentials.Certificate(dir_path + '/serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
'databaseURL': *DB_URL*
})
def db(event):
print('Firebase event detected: ')
print('Path: ' + event.path)
print('Data: ' + event.data)
print('Event type: ' + event.event_type)
now = datetime.datetime.now()
human_timestamp = '{y}-{mon}-{d} {h}:{min}:{s}'.format(
y=now.year,
mon=now.month,
d=now.day,
h=now.hour,
min=now.minute,
s=now.second
)
print(human_timestamp)
if __name__ == "__main__":
loc_path = *LOC_PATH*
listener = firebase_admin.db.reference(loc_path).listen(db)
try:
while True:
pass
except KeyboardInterrupt:
listener.close()
我将其运行了一个小时,并看到以下输出:
Firebase event detected:
Path: /
Data: test
Type: put
2019-2-3 9:11:58
Firebase event detected:
Path: /
Data: test
Type: put
2019-2-3 10:12:4