Мы работаем над мобильным приложением, в котором мы используем FireBase, мы используем FireStore в качестве нашей базы данных и поддерживаем данные в коллекциях, то есть мы должны публиковать данные в Salesforce всякий раз, когда происходят какие-либо изменения или обновления в любом из Для этого мы создали триггеры пожарных хранилищ в облаке, используя python 3.7, используя эту ссылку Нажмите здесь , облачная функция имеет тип триггера как Cloud Firestore (Beta) и Тип события как provider / cloud.firestore / eventTypes / document.write с использованием {wildcard} с путем как Shipments / {ShipmentId} , и оно запускается всякий раз, когда в коллекциях отправлений произошли изменения, изменив мой код в файле main.py на
import requests
def TriggerShipmentChange(event, context):
resource_string = context.resource
print("function trigger by change to",{resource_string})
data = event
if data["oldValue"] == {} and data["updateMask"] == {}:
print("New shipment record $$$ Created $$$", data["value"])
elif data["updateMask"] == {} and data["value"] == {}:
print("Shipment record is $$$ deleted $$$", data["oldValue"])
elif data["oldValue"] != {} and data["value"] != {} and data["updateMask"] != {}:
print("Shipment record is $$$ updated $$$ and updated fields", data["updateMask"]["fieldPaths"])
print("updated values", data["value"])
else:
print("Function Response", data)
print("update details in backend")
URL ='http://*****.herokuapp.com'
result = requests.get(URL)
print("response", result.status_code, result.content)
и обновив файл require.txt с
requests==2.22.0
и изменив функцию на выполнить в TriggerShipmentChange
Я могу выполнить эти триггеры и получить данные обновленной записи и, следовательно, планирую опубликовать Здесь я использую внешнюю службу для публикации данных, но сначала, чтобы проверить соединение, я только что сделал запрос на получение, который выдает ошибку. Здесь мне нужно отправить запрос на внешний сервер, который находится в Heroku. Я приложу свои журналы
Function execution took 101 ms, finished with status: 'crash'
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 157, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/env/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 61, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/opt/python3.7/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/python3.7/lib/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/python3.7/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/python3.7/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/python3.7/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/opt/python3.7/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 184, in connect
conn = self._new_conn()
File "/env/local/lib/python3.7/site-packages/urllib3/connection.py", line 169, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/env/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/env/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='nltmsfirst.herokuapp.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function
_function_handler.invoke_user_function(event_object)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function
return call_user_function(request_or_event)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function
event_context.Context(**request_or_event.context))
File "/user_code/main.py", line 35, in TriggerShipmentChange
result = requests.get(URL)
File "/env/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/env/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/env/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/env/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='nltmsfirst.herokuapp.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7eef49645410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
E
updated values {'createTime': '2020-01-28T09:56:01.307748Z', 'fields': {'ShipmentId': {'stringValue': '1234'}, 'Status': {'stringValue': 'Tendered'}}, 'name': 'projects/tablet-app-b9154/databases/(default)/documents/App/Dnow/Shipments/SR#1234', 'updateTime': '2020-01-29T08:24:48.233535Z'}
Shipment record is $$$ updated $$$ and updated fields ['Status']
function trigger by change to {'projects/tablet-app-b9154/databases/(default)/documents/App/Dnow/Shipments/SR#1234'}
Function execution started D
Я не хочу сейчас создавать новую функцию HTTP, я просто хочу, чтобы приведенный выше код работал, есть ли способ сделать это, если нет, то как я могу это сделать? обновить эти обновленные данные записи на другом сервере?