本文整理汇总了Python中util.get_worker_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_worker_name函数的具体用法?Python get_worker_name怎么用?Python get_worker_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_worker_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: database_environment_migrate_rollback
def database_environment_migrate_rollback(self, migrate, task):
task = TaskHistory.register(
request=self.request, task_history=task, user=task.user,
worker_name=get_worker_name()
)
from tasks_database_migrate import rollback_database_environment_migrate
rollback_database_environment_migrate(migrate, task)
示例2: remove_database_old_backups
def remove_database_old_backups(self):
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request,
worker_name=worker_name, user=None)
backup_retention_days = Configuration.get_by_name_as_int('backup_retention_days')
LOG.info("Removing backups older than %s days" % (backup_retention_days))
backup_time_dt = date.today() - timedelta(days=backup_retention_days)
snapshots = Snapshot.objects.filter(start_at__lte=backup_time_dt, purge_at__isnull = True, instance__isnull = False, snapshopt_id__isnull = False)
msgs = []
status = TaskHistory.STATUS_SUCCESS
if len(snapshots) == 0:
msgs.append("There is no snapshot to purge")
for snapshot in snapshots:
try:
remove_snapshot_backup(snapshot=snapshot)
msg = "Backup %s removed" % (snapshot)
LOG.info(msg)
except:
msg = "Error removing backup %s" % (snapshot)
status = TaskHistory.STATUS_ERROR
LOG.error(msg)
msgs.append(msg)
task_history.update_status_for(status, details="\n".join(msgs))
return
示例3: database_notification
def database_notification(self):
LOG.info("retrieving all teams and sending database notification")
teams = Team.objects.all()
msgs = {}
for team in teams:
###############################################
# create task
###############################################
msgs[team] = analyzing_notification_for_team(team=team)
###############################################
try:
LOG.info("Messages: ")
LOG.info(msgs)
worker_name = get_worker_name()
task_history = TaskHistory.register(
request=self.request, user=None, worker_name=worker_name)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="\n".join(
str(key) + ': ' + ', '.join(value) for key, value in msgs.items()))
except Exception as e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
return
示例4: databaseinfra_notification
def databaseinfra_notification(self, user=None):
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=user, worker_name= worker_name)
threshold_infra_notification = Configuration.get_by_name_as_int("threshold_infra_notification", default=0)
if threshold_infra_notification <= 0:
LOG.warning("database infra notification is disabled")
return
# Sum capacity per databseinfra with parameter plan, environment and engine
infras = DatabaseInfra.objects.values('plan__name', 'environment__name', 'engine__engine_type__name',
'plan__provider').annotate(capacity=Sum('capacity'))
for infra in infras:
# total database created in databaseinfra per plan, environment and engine
used = DatabaseInfra.objects.filter(plan__name=infra['plan__name'],
environment__name=infra['environment__name'],
engine__engine_type__name=infra['engine__engine_type__name']).aggregate(
used=Count('databases'))
# calculate the percentage
percent = int(used['used'] * 100 / infra['capacity'])
if percent >= threshold_infra_notification and infra['plan__provider'] != Plan.CLOUDSTACK:
LOG.info('Plan %s in environment %s with %s%% occupied' % (
infra['plan__name'], infra['environment__name'], percent))
LOG.info("Sending database infra notification...")
context = {}
context['plan'] = infra['plan__name']
context['environment'] = infra['environment__name']
context['used'] = used['used']
context['capacity'] = infra['capacity']
context['percent'] = percent
email_notifications.databaseinfra_ending(context=context)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS,
details='Databaseinfra Notification successfully sent to dbaas admins!')
return
示例5: make_databases_backup
def make_databases_backup(self):
LOG.info("Making databases backups")
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request,
worker_name=worker_name, user=None)
msgs = []
status = TaskHistory.STATUS_SUCCESS
databaseinfras = DatabaseInfra.objects.filter(plan__provider=Plan.CLOUDSTACK)
error = {}
for databaseinfra in databaseinfras:
instances = Instance.objects.filter(databaseinfra=databaseinfra)
for instance in instances:
if not instance.databaseinfra.get_driver().check_instance_is_eligible_for_backup(instance):
LOG.info('Instance %s is not eligible for backup' % (str(instance)))
continue
try:
if make_instance_snapshot_backup(instance = instance, error = error):
msg = "Backup for %s was successful" % (str(instance))
LOG.info(msg)
else:
status = TaskHistory.STATUS_ERROR
msg = "Backup for %s was unsuccessful. Error: %s" % (str(instance), error['errormsg'])
LOG.error(msg)
print msg
except Exception, e:
status = TaskHistory.STATUS_ERROR
msg = "Backup for %s was unsuccessful. Error: %s" % (str(instance), str(e))
LOG.error(msg)
msgs.append(msg)
示例6: update_instances_status
def update_instances_status(self):
LOG.info("Retrieving all databaseinfras")
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=None, worker_name=worker_name)
try:
infras = DatabaseInfra.objects.all()
msgs = []
for databaseinfra in infras:
LOG.info("Retrieving all instances for {}".format(databaseinfra))
for instance in Instance.objects.filter(databaseinfra=databaseinfra, is_arbiter=False):
if instance.check_status():
instance.status = Instance.ALIVE
else:
instance.status = Instance.DEAD
instance.save()
msg = "\nUpdating instance status, instance: {}, status: {}".format(
instance, instance.status)
msgs.append(msg)
LOG.info(msg)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="\n".join(
value for value in msgs))
except Exception, e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
示例7: database_notification
def database_notification(self):
"""
Create tasks for database notification by team
if threshold_database_notification <= 0, the notification is disabled.
"""
# get all teams and for each one create a new task
LOG.info("retrieving all teams and sendind database notification")
teams = Team.objects.all()
msgs = {}
for team in teams:
###############################################
# create task
###############################################
msgs[team] = database_notification_for_team(team=team)
###############################################
try:
LOG.info("Messages: ")
LOG.info(msgs)
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=None, worker_name=worker_name)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="\n".join(
str(key) + ': ' + ', '.join(value) for key, value in msgs.items()))
except Exception, e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
示例8: update_database_status
def update_database_status(self):
LOG.info("Retrieving all databases")
try:
worker_name = get_worker_name()
task_history = TaskHistory.register(
request=self.request, user=None, worker_name=worker_name)
databases = Database.objects.all()
msgs = []
for database in databases:
if database.database_status.is_alive:
database.status = Database.ALIVE
instances_status = database.databaseinfra.check_instances_status()
if instances_status == database.databaseinfra.ALERT:
database.status = Database.ALERT
else:
database.status = Database.DEAD
database.save()
msg = "\nUpdating status for database: {}, status: {}".format(
database, database.status)
msgs.append(msg)
LOG.info(msg)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="\n".join(
value for value in msgs))
except Exception, e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
示例9: update_database_used_size
def update_database_used_size(self):
LOG.info("Retrieving all databases")
try:
worker_name = get_worker_name()
task_history = TaskHistory.register(
request=self.request, user=None, worker_name=worker_name)
databases = Database.objects.all()
msgs = []
for database in databases:
if database.database_status:
database.used_size_in_bytes = float(
database.database_status.used_size_in_bytes)
else:
database.used_size_in_bytes = 0.0
database.save()
msg = "\nUpdating used size in bytes for database: {}, used size: {}".format(
database, database.used_size_in_bytes)
msgs.append(msg)
LOG.info(msg)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="\n".join(
value for value in msgs))
except Exception, e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
示例10: purge_task_history
def purge_task_history(self):
try:
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=None, worker_name=worker_name)
now = datetime.datetime.now()
retention_days = Configuration.get_by_name_as_int('task_history_retention_days')
n_days_before = now - datetime.timedelta(days=retention_days)
tasks_to_purge = TaskHistory.objects.filter(task_name__in=['notification.tasks.database_notification',
'notification.tasks.database_notification_for_team',
'notification.tasks.update_database_status',
'notification.tasks.update_database_used_size',
'notification.tasks.update_instances_status',
'system.tasks.set_celery_healthcheck_last_update']
, ended_at__lt=n_days_before
, task_status__in=["SUCCESS", "ERROR"])
tasks_to_purge.delete()
task_history.update_status_for(TaskHistory.STATUS_SUCCESS,
details='Purge succesfully done!')
except Exception, e:
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
示例11: monitor_acl_job
def monitor_acl_job(self,database, job_id, bind_address, bind_status=models.CREATED , user=None):
if not user:
user = self.request.args[-1]
AuditRequest.new_request("create_database",user, "localhost")
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=user, worker_name=worker_name)
LOG.info("id: %s | task: %s | kwargs: %s | args: %s" % (self.request.id, self.request.task, self.request.kwargs, str(self.request.args)))
task_history.update_details(persist=True, details="Loading Process...")
try:
LOG.debug("database: {}, job_id: {}, bind_address: {}, bind_status: {}, user: {}".format(database, job_id, bind_address, bind_status, user))
status = tasks.monitor_acl_job(database, job_id, bind_address,)
LOG.debug("Job status return: {}".format(status))
if status:
from dbaas_aclapi.util import update_bind_status
LOG.info("Updating Bind Status")
update_bind_status(database, bind_address, bind_status)
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Bind created successfully')
return
else:
raise Exception, "Error when monitoring the Bind Process"
except Exception, e:
LOG.info("DatabaseBindMonitoring ERROR: {}".format(e))
task_history.update_status_for(TaskHistory.STATUS_ERROR, details='Bind could not be granted')
return
示例12: resize_database
def resize_database(self, database, cloudstackpack, task_history=None,user=None):
AuditRequest.new_request("resize_database", user, "localhost")
try:
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, task_history=task_history,
user=user, worker_name=worker_name)
from util.providers import resize_database
result = resize_database(database = database, cloudstackpack = cloudstackpack, task = task_history)
if result['created']==False:
if 'exceptions' in result:
error = "\n".join(": ".join(err) for err in result['exceptions']['error_codes'])
traceback = "\nException Traceback\n".join(result['exceptions']['traceback'])
error = "{}\n{}\n{}".format(error, traceback, error)
else:
error = "Something went wrong."
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=error)
else:
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details='Resize successfully done.')
except Exception, e:
error = "Resize Database ERROR: {}".format(e)
LOG.error(error)
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=error)
示例13: node_zone_migrate_rollback
def node_zone_migrate_rollback(self, migrate, task):
task = TaskHistory.register(
request=self.request, task_history=task, user=task.user,
worker_name=get_worker_name()
)
from tasks_migrate import rollback_node_zone_migrate
rollback_node_zone_migrate(migrate, task)
示例14: remove_database_old_backups
def remove_database_old_backups(self):
worker_name = get_worker_name()
task_history = TaskHistory.register(
request=self.request, worker_name=worker_name, user=None
)
task_history.relevance = TaskHistory.RELEVANCE_WARNING
snapshots = []
for env in Environment.objects.all():
snapshots += get_snapshots_by_env(env)
msgs = []
status = TaskHistory.STATUS_SUCCESS
if len(snapshots) == 0:
msgs.append("There is no snapshot to purge")
for snapshot in snapshots:
try:
remove_snapshot_backup(snapshot=snapshot, msgs=msgs)
except Exception as e:
msg = "Error removing backup {}. Error: {}".format(snapshot, e)
status = TaskHistory.STATUS_ERROR
LOG.error(msg)
msgs.append(msg)
task_history.update_status_for(status, details="\n".join(msgs))
return
示例15: _create_database_rollback
def _create_database_rollback(self, rollback_from, task, user):
task = TaskHistory.register(
request=self.request, task_history=task, user=user,
worker_name=get_worker_name()
)
from tasks_create_database import rollback_create
rollback_create(rollback_from, task, user)