Skip to content

Commit

Permalink
support function instanceConcurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
rockuw committed Dec 4, 2019
1 parent 4a35da7 commit 90b6364
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fc2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ def create_function(
self, serviceName, functionName, runtime, handler,
initializer=None, initializationTimeout=30,
codeZipFile=None, codeDir=None, codeOSSBucket=None, codeOSSObject=None,
description=None, memorySize=256, timeout=60, headers={}, environmentVariables=None):
description=None, memorySize=256, timeout=60, headers={}, environmentVariables=None,
instanceConcurrency=None):
"""
Create a function.
:param serviceName: (required, string) the name of the service that the function belongs to.
Expand All @@ -447,6 +448,7 @@ def create_function(
:param timeout: (optional, integer) the max execution time of the function, in second.
:param initializationTimeout: (optional, integer) the max execution time of the initializer, in second.
:param environmentVariables: (optional, dict) the environment variables of the function, both key and value are string type.
:param instanceConcurrency: (optional, integer) the instance concurrency of the function
:param headers, optional
1, 'x-fc-trace-id': string (a uuid to do the request tracing)
2, user define key value
Expand Down Expand Up @@ -523,6 +525,9 @@ def create_function(
if environmentVariables != None:
payload['environmentVariables'] = environmentVariables

if instanceConcurrency != None:
payload['instanceConcurrency'] = instanceConcurrency

r = self._do_request(method, path, headers,
body=json.dumps(payload).encode('utf-8'))
# 'etag' now in headers
Expand All @@ -533,7 +538,7 @@ def update_function(
initializer=None, initializationTimeout=None,
codeZipFile=None, codeDir=None, codeOSSBucket=None, codeOSSObject=None,
description=None, handler=None, memorySize=None, runtime=None, timeout=None,
headers={}, environmentVariables=None):
headers={}, environmentVariables=None, instanceConcurrency=None):
"""
Update the function.
:param serviceName: (required, string) the name of the service that the function belongs to.
Expand All @@ -551,6 +556,7 @@ def update_function(
:param initializationTimeout: (optional, integer) the max execution time of the initializer, in second.
:param etag: (optional, string) delete the service only when matched the given etag.
:param environmentVariables: (optional, dict) the environment variables of the function, both key and value are string type.
:param instanceConcurrency: (optional, integer) the instance concurrency of the function
:param headers, optional
1, 'x-fc-trace-id': string (a uuid to do the request tracing)
2, 'if-match': string (update the function only when matched the given etag.)
Expand Down Expand Up @@ -632,6 +638,9 @@ def update_function(
if environmentVariables != None:
payload['environmentVariables'] = environmentVariables

if instanceConcurrency != None:
payload['instanceConcurrency'] = instanceConcurrency

r = self._do_request(method, path, headers,
body=json.dumps(payload).encode('utf-8'))
# 'etag' now in headers
Expand Down
17 changes: 17 additions & 0 deletions test/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ def test_create(self):
function2 = function2.data
self.assertEqual(function2['environmentVariables']['testKey'], 'testValue')

def test_instance_concurrency(self):
# test create function with instanceConcurrency
function_name= 'test_create_' + ''.join(random.choice(string.ascii_lowercase) for _ in range(8))
desc = u'test for initializer'
resp = self.client.create_function(
self.serviceName, function_name,
handler='main.my_handler', runtime='nodejs10', codeDir='test/counter', initializer='main.my_initializer',
description=desc, environmentVariables={'testKey': 'testValue'}, instanceConcurrency=2)
self.assertEqual(2, resp.data['instanceConcurrency'])

# update function with instanceConcurrency
resp = self.client.update_function(self.serviceName, function_name, instanceConcurrency=10)
self.assertEqual(10, resp.data['instanceConcurrency'])

# delete the function
self.client.delete_function(self.serviceName, function_name)

def check_function(self, function, functionName, desc, runtime = 'python2.7', initializer = None, initializationTimeout = None):
etag = function.headers['etag']
self.assertNotEqual(etag, '')
Expand Down

0 comments on commit 90b6364

Please sign in to comment.