I'm building a google cloud function which is launching every 1mins. The purpose is to get data from my database (firebase) and to delete this data if the date of the post is superior to one hour ago.
I was thinking about making a firebase cloud function, and use the settimeout function after one hour. Unfortunately its not possible aparently. So i decided to use the cron functions of gcloud.
Here is my main.py.
import webapp2
from gcloud import datastore
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate('key.json')
try:
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://#########.firebaseio.com/'
})
except:
print('no need for init firebase')
# As an admin, the app has access to read and write all data, regradless of Security Rules
ref = db.reference('/')
class HourCronPage(webapp2.RequestHandler):
def get(self):
ref.child("test").delete()
app = webapp2.WSGIApplication([
('/timer', HourCronPage),
], debug=True)
Here is the error i get from the gcloud console and i've no idea how to solve this:
('Connection broken: IncompleteRead(14 bytes read)', IncompleteRead(14 bytes read)) (/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py:1552)
Traceback (most recent call last):
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/main.py", line 25, in get
ref.child("test").delete()
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/firebase_admin/db.py", line 282, in delete
self._client.request('delete', self._add_suffix())
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/firebase_admin/db.py", line 774, in request
return super(_Client, self).request(method, url, **kwargs)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/firebase_admin/_http_client.py", line 84, in request
resp = self._session.request(method, self._base_url + url, **kwargs)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/auth/transport/requests.py", line 198, in request
self._auth_request, method, url, request_headers)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/auth/credentials.py", line 121, in before_request
self.refresh(request)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/oauth2/service_account.py", line 322, in refresh
request, self._token_uri, assertion)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/oauth2/_client.py", line 145, in jwt_grant
response_data = _token_endpoint_request(request, token_uri, body)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/oauth2/_client.py", line 106, in _token_endpoint_request
method='POST', url=token_uri, headers=headers, body=body)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/google/auth/transport/requests.py", line 124, in __call__
six.raise_from(new_exc, caught_exc)
File "/base/data/home/apps/s~instavice-application/20180408t195049.408875809865949267/lib/six.py", line 737, in raise_from
raise value
TransportError: ('Connection broken: IncompleteRead(14 bytes read)', IncompleteRead(14 bytes read))
Anyone has an idea?
Thank you guys so much in advance.