Adding support to reload environment variables (#377)

* Adding support to reload environment variables

* Fixing code quality issues

* Getting rid of white space from blank lines
This commit is contained in:
Maheer Iqbal 2019-05-01 14:04:59 -07:00 коммит произвёл GitHub
Родитель 49e6cf1a53
Коммит c67f4de5e3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 33 добавлений и 0 удалений

Просмотреть файл

@ -9,6 +9,7 @@ import logging
import queue
import threading
import traceback
import os
import grpc
import pkg_resources
@ -350,6 +351,36 @@ class Dispatcher(metaclass=DispatcherMeta):
status=protos.StatusResult.Failure,
exception=self._serialize_exception(ex))))
async def _handle__function_environment_reload_request(self, req):
try:
logger.info('Received FunctionEnvironmentReloadRequest, '
'request ID: %s', self.request_id)
func_env_reload_request = req.function_environment_reload_request
env_vars = func_env_reload_request.environment_variables
for var in env_vars:
os.environ[var] = env_vars[var]
success_response = protos.FunctionEnvironmentReloadResponse(
result=protos.StatusResult(
status=protos.StatusResult.Success))
return protos.StreamingMessage(
request_id=self.request_id,
function_environment_reload_response=success_response)
except Exception as ex:
failure_response = protos.FunctionEnvironmentReloadResponse(
result=protos.StatusResult(
status=protos.StatusResult.Failure,
exception=self._serialize_exception(ex)))
return protos.StreamingMessage(
request_id=self.request_id,
function_environment_reload_response=failure_response)
def __run_sync_func(self, invocation_id, func, params):
# This helper exists because we need to access the current
# invocation_id from ThreadPoolExecutor's threads.

Просмотреть файл

@ -11,6 +11,8 @@ from .FunctionRpc_pb2 import ( # NoQA
RpcFunctionMetadata,
FunctionLoadRequest,
FunctionLoadResponse,
FunctionEnvironmentReloadRequest,
FunctionEnvironmentReloadResponse,
InvocationRequest,
InvocationResponse,
WorkerHeartbeat,