本文整理汇总了Python中models.Actor.from_db方法的典型用法代码示例。如果您正苦于以下问题:Python Actor.from_db方法的具体用法?Python Actor.from_db怎么用?Python Actor.from_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Actor
的用法示例。
在下文中一共展示了Actor.from_db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def get(self, actor_id, ch_name):
try:
Actor.from_db(actors_store[actor_id])
except KeyError:
raise WorkerException("actor not found: {}'".format(actor_id))
try:
worker = get_worker(actor_id, ch_name)
except WorkerException as e:
raise APIException(e.message, 404)
return ok(result=worker, msg="Worker retrieved successfully.")
示例2: post
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def post(self, actor_id):
"""Add new permissions for an actor"""
try:
Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
args = self.validate_post()
add_permission(args['user'], actor_id, args['level'])
permissions = get_permissions(actor_id)
return ok(result=permissions, msg="Permission added successfully.")
示例3: get
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def get(self, actor_id):
try:
Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
try:
permissions = get_permissions(actor_id)
except PermissionsException as e:
raise APIException(e.message, 404)
return ok(result=permissions, msg="Permissions retrieved successfully.")
示例4: get
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def get(self, actor_id):
dbid = Actor.get_dbid(g.tenant, actor_id)
try:
Actor.from_db(actors_store[dbid])
except KeyError:
raise APIException("actor not found: {}'".format(actor_id), 400)
try:
workers = Worker.get_workers(dbid)
except WorkerException as e:
raise APIException(e.msg, 404)
result = []
for id, worker in workers.items():
worker.update({'id': id})
result.append(worker)
return ok(result=result, msg="Workers retrieved successfully.")
示例5: get
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def get(self, actor_id):
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
return ok(result=actor, msg="Actor retrieved successfully.")
示例6: put
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def put(self, actor_id):
dbid = Actor.get_dbid(g.tenant, actor_id)
try:
actor = Actor.from_db(actors_store[dbid])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
previous_image = actor.image
args = self.validate_put(actor)
args['tenant'] = g.tenant
update_image = False
if args['image'] == previous_image:
args['status'] = actor.status
else:
update_image = True
args['status'] = SUBMITTED
args['api_server'] = g.api_server
args['owner'] = g.user
actor = Actor(**args)
actors_store[actor.db_id] = actor.to_db()
if update_image:
ch = CommandChannel()
ch.put_cmd(actor_id=actor.db_id, image=actor.image, tenant=args['tenant'])
# return ok(result={'update_image': str(update_image)},
# msg="Actor updated successfully.")
return ok(result=actor.display(),
msg="Actor updated successfully.")
示例7: post
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def post(self, actor_id):
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
args = self.validate_post()
Execution.add_execution(actor_id, args)
return ok(result=actor, msg="Actor execution added successfully.")
示例8: manage_workers
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def manage_workers(actor_id):
"""Scale workers for an actor if based on message queue size and policy."""
print("Entering manage_workers for {}".format(actor_id))
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
print("Did not find actor; returning.")
return
workers = Worker.get_workers(actor_id)
示例9: get
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def get(self, actor_id):
# check that actor exists
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
# TODO
# retrieve pending messages from the queue
return ok(result={'messages': []})
示例10: post
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def post(self, actor_id):
dbid = Actor.get_dbid(g.tenant, actor_id)
args = self.validate_post()
state = args['state']
try:
actor = Actor.from_db(actors_store[dbid])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
actors_store.update(dbid, 'state', state)
return ok(result=actor.display(), msg="State updated successfully.")
示例11: check_new_params
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def check_new_params(self, cmd):
valid, msg = self.check_common(cmd)
# validate the actor_id
try:
actor = Actor.from_db(actors_store[cmd.get('actor_id')])
except KeyError:
return False, "Unable to look up actor with id: {}".format(cmd.get('actor_id')), None
# validate the worker id
try:
Worker.get_worker(actor_id=cmd.get('actor_id'), ch_name=cmd.get('worker_id'))
except WorkerException as e:
return False, "Unable to look up worker: {}".format(e.msg), None
return valid, msg, actor.owner
示例12: post
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def post(self, actor_id):
"""Start new workers for an actor"""
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException("actor not found: {}'".format(actor_id), 404)
args = self.validate_post()
num = args.get("num")
if not num or num == 0:
num = 1
ch = CommandChannel()
ch.put_cmd(actor_id=actor.id, image=actor.image, num=num, stop_existing=False)
return ok(result=None, msg="Scheduled {} new worker(s) to start.".format(str(num)))
示例13: delete
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def delete(self, actor_id):
id = Actor.get_dbid(g.tenant, actor_id)
shutdown_workers(id)
try:
actor = Actor.from_db(actors_store[id])
executions = actor.get('executions') or {}
for ex_id, val in executions.items():
del logs_store[ex_id]
except KeyError:
print("Did not find actor with id: {}".format(id))
del actors_store[id]
del permissions_store[id]
return ok(result=None, msg='Actor deleted successfully.')
示例14: put
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def put(self, actor_id):
try:
actor = Actor.from_db(actors_store[actor_id])
except KeyError:
raise APIException(
"actor not found: {}'".format(actor_id), 404)
args = self.validate_put()
update_image = False
args['name'] = actor['name']
args['id'] = actor['id']
args['executions'] = actor['executions']
args['state'] = actor['state']
if args['image'] == actor.image:
args['status'] = actor.status
else:
update_image = True
args['status'] = SUBMITTED
actor = Actor(args)
actors_store[actor.id] = actor.to_db()
if update_image:
ch = CommandChannel()
ch.put_cmd(actor_id=actor.id, image=actor.image)
return ok(result=actor, msg="Actor updated successfully.")
示例15: subscribe
# 需要导入模块: from models import Actor [as 别名]
# 或者: from models.Actor import from_db [as 别名]
def subscribe(tenant,
actor_id,
api_server,
client_id,
client_secret,
access_token,
refresh_token,
worker_ch):
"""
Main loop for the Actor executor worker. Subscribes to the actor's inbox and executes actor
containers when message arrive. Also subscribes to the worker channel for future communications.
:return:
"""
actor_ch = ActorMsgChannel(actor_id)
ag = None
if api_server and client_id and client_secret and access_token and refresh_token:
ag = Agave(api_server=api_server,
token=access_token,
refresh_token=refresh_token,
api_key=client_id,
api_secret=client_secret)
else:
print("Not creating agave client.")
t = threading.Thread(target=process_worker_ch, args=(tenant, worker_ch, actor_id, actor_ch, ag))
t.start()
print("Worker subscribing to actor channel...")
global keep_running
while keep_running:
Worker.update_worker_status(actor_id, worker_ch.name, READY)
try:
msg = actor_ch.get(timeout=2)
except channelpy.ChannelTimeoutException:
continue
except channelpy.ChannelClosedException:
print("Channel closed, worker exiting...")
keep_running = False
sys.exit()
print("Received message {}. Starting actor container...".format(str(msg)))
# the msg object is a dictionary with an entry called message and an arbitrary
# set of k:v pairs coming in from the query parameters.
message = msg.pop('message', '')
actor = Actor.from_db(actors_store[actor_id])
execution_id = msg['_abaco_execution_id']
privileged = False
if actor['privileged'] == 'TRUE':
privileged = True
environment = actor['default_environment']
print("Actor default environment: {}".format(environment))
print("Actor privileged: {}".format(privileged))
# overlay the default_environment registered for the actor with the msg
# dictionary
environment.update(msg)
environment['_abaco_access_token'] = ''
# if we have an agave client, get a fresh set of tokens:
if ag:
try:
ag.token.refresh()
token = ag.token.token_info['access_token']
environment['_abaco_access_token'] = token
print("Refreshed the tokens. Passed {} to the environment.".format(token))
except Exception as e:
print("Got an exception trying to get an access token: {}".format(e))
else:
print("Agave client `ag` is None -- not passing access token.")
print("Passing update environment: {}".format(environment))
try:
stats, logs = execute_actor(actor_id, worker_ch, image, message,
environment, privileged)
except DockerStartContainerError as e:
print("Got DockerStartContainerError: {}".format(str(e)))
Actor.set_status(actor_id, ERROR)
continue
# add the execution to the actor store
print("Actor container finished successfully. Got stats object:{}".format(str(stats)))
Execution.finalize_execution(actor_id, execution_id, COMPLETE, stats)
print("Added execution: {}".format(execution_id))
Execution.set_logs(execution_id, logs)
Worker.update_worker_execution_time(actor_id, worker_ch.name)