1

I am running a Python script to intercept new Firebase documents, and update a paramter, and then keep listening.

I am hoping to keep it running 24/7 and doing this continuously. Here is the code I am running:

import datetime
import time
from time import sleep
from google.cloud import firestore
import google.cloud.exceptions
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore 
from pprint import pprint
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="fbkey.json"

# Use a service account
cred = credentials.Certificate('fbkey.json')
firebase_admin.initialize_app(cred)

db = firestore.client()

def setAsReady(docId):
    ref = db.collection(u'tasks').document(docId)
    ref.update({u'status': 'READY'})

def on_snapshot(col_snapshot, changes, read_time):
    for doc in changes:
        newDocId = doc.document.id
        print(newDocId)
        setAsReady(newDocId)

col_query = db.collection(u'tasks').where(u'status', u'==', u'NEW')
query_watch = col_query.on_snapshot(on_snapshot)

time.sleep(500000000)

Right now I am using time.sleep(5000000000) to keep the script running, though, I assume this is a bad idea.

I want to run this script an Ubuntu server, and so I put this in a screen window, and it runs well for half an hour or so, though later I get this error:

  File "/usr/local/lib/python3.5/dist-packages/grpc/_channel.py", line 358, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.INTERNAL
        details = "Received RST_STREAM with error code 0"
        debug_error_string = "{"created":"@1565213741.785723473","description":"Error received from peer ipv4:172.217.14.202:443","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Received RST_STREAM with error code 0","grpc_status":13}"
>
Exception in thread Thread-OnRpcTerminated:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/google/cloud/firestore_v1/watch.py", line 290, in close
    raise reason
google.api_core.exceptions.InternalServerError: 500 Received RST_STREAM with error code 0
unicornication
  • 635
  • 2
  • 7
  • 26

0 Answers0