Description
[READ] Step 1: Are you in the right place?
- For issues or feature requests related to the code in this repository
file a Github issue.- If this is a feature request make sure the issue title starts with "FR:".
- For general technical questions, post a question on StackOverflow
with the firebase tag. - For general Firebase discussion, use the firebase-talk
google group. - For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Operating System version: Linux raspberrypi 4.14.79+ #1159 Sun Nov 4 17:28:08 GMT 2018 armv6l GNU/Linux
- Firebase SDK version: 2.15.1
- Library version: _____ (not sure how to find, will add if I do)
- Firebase Product: database
[REQUIRED] Step 3: Describe the problem
If I setup a new reference listener using the listen() method, the listener will automatically fire each hour, even if there are no changes to the database. I only expect the listener to fire when there are changes at the database reference path
I originally reported this issue to the Firebase support team, and this is the response they provided:
Apparently, the listen() method of the Admin SDK for Python is an experimental feature. Given the nature of the error and that this is using the streaming REST API under the hood, it is likely that access tokens expire every hour and the HTTP connection has to be refreshed with a new token.
Steps to reproduce:
Set up a new reference listener using firebase_admin.db.reference(loc_path).listen(db)
and monitor output. Listener will fire every hour after it was originally started, even if there are no changes in the database.
See this screenshot for sample output:
Relevant Code:
# 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 = 'test/key'
listener = firebase_admin.db.reference(loc_path).listen(db)
try:
while True:
pass
except KeyboardInterrupt:
listener.close()