本文整理汇总了Python中notification.models.TaskHistory类的典型用法代码示例。如果您正苦于以下问题:Python TaskHistory类的具体用法?Python TaskHistory怎么用?Python TaskHistory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskHistory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register_task
def register_task(self):
task_history = TaskHistory()
task_history.task_id = datetime.now().strftime("%Y%m%d%H%M%S")
task_history.task_name = "switch_masters_in_zone"
task_history.relevance = TaskHistory.RELEVANCE_WARNING
task_history.task_status = TaskHistory.STATUS_RUNNING
task_history.context = {'hostname': gethostname()}
task_history.user = 'admin'
task_history.save()
return task_history
开发者ID:globocom,项目名称:database-as-a-service,代码行数:10,代码来源:switch_all_masters_in_zone.py
示例2: 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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:tasks.py
示例3: 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
开发者ID:globocom,项目名称:database-as-a-service,代码行数:26,代码来源:tasks.py
示例4: 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
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:26,代码来源:send_email.py
示例5: make_databases_backup
def make_databases_backup(self):
LOG.info("Making databases backups")
task_history = TaskHistory.register(request=self.request, 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)
开发者ID:Milstein,项目名称:database-as-a-service,代码行数:32,代码来源:tasks.py
示例6: test_can_get_waiting_tasks
def test_can_get_waiting_tasks(self):
self.task.task_status = TaskHistory.STATUS_WAITING
self.task.save()
tasks = TaskHistory.waiting_tasks()
self.assertIsNotNone(tasks)
self.assertIn(self.task, tasks)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:test_task_history.py
示例7: test_can_get_running_tasks
def test_can_get_running_tasks(self):
self.task.task_status = TaskHistory.STATUS_RUNNING
self.task.save()
tasks = TaskHistory.running_tasks()
self.assertIsNotNone(tasks)
self.assertIn(self.task, tasks)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:test_task_history.py
示例8: 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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:7,代码来源:tasks.py
示例9: remove_database_old_backups
def remove_database_old_backups(self):
task_history = TaskHistory.register(request=self.request, 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
开发者ID:Milstein,项目名称:database-as-a-service,代码行数:28,代码来源:tasks.py
示例10: _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)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:8,代码来源:tasks.py
示例11: delete_model
def delete_model(modeladmin, request, obj):
LOG.debug("Deleting {}".format(obj))
database = obj
if database.is_in_quarantine:
if database.plan.provider == database.plan.CLOUDSTACK:
LOG.debug(
"call destroy_database - name=%s, team=%s, project=%s, user=%s" % (
database.name, database.team, database.project, request.user))
task_history = TaskHistory()
task_history.task_name="destroy_database"
task_history.task_status= task_history.STATUS_WAITING
task_history.arguments="Database name: {}".format(database.name)
task_history.user= request.user
task_history.save()
destroy_database.delay(database=database,
task_history=task_history,
user=request.user
)
url = reverse('admin:notification_taskhistory_changelist')
else:
database.delete()
else:
database.delete()
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:29,代码来源:database.py
示例12: node_zone_migrate
def node_zone_migrate(
self, host, zone, new_environment, task, since_step=None, step_manager=None
):
task = TaskHistory.register(
request=self.request, task_history=task, user=task.user,
worker_name=get_worker_name()
)
from tasks_migrate import node_zone_migrate
node_zone_migrate(host, zone, new_environment, task, since_step, step_manager=step_manager)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:9,代码来源:tasks.py
示例13: restore_snapshot
def restore_snapshot(self, database, snapshot, user, task_history):
from dbaas_nfsaas.models import HostAttr
LOG.info("Restoring snapshot")
worker_name = get_worker_name()
task_history = models.TaskHistory.objects.get(id=task_history)
task_history = TaskHistory.register(request=self.request, task_history=task_history,
user=user, worker_name=worker_name)
databaseinfra = database.databaseinfra
snapshot = Snapshot.objects.get(id=snapshot)
snapshot_id = snapshot.snapshopt_id
host_attr = HostAttr.objects.get(nfsaas_path=snapshot.export_path)
host = host_attr.host
host_attr = HostAttr.objects.get(host=host, is_active=True)
export_id = host_attr.nfsaas_export_id
export_path = host_attr.nfsaas_path
steps = RESTORE_SNAPSHOT_SINGLE
if databaseinfra.plan.is_ha and databaseinfra.engine_name == 'mysql':
steps = RESTORE_SNAPSHOT_MYSQL_HA
not_primary_instances = databaseinfra.instances.exclude(hostname=host).exclude(instance_type__in=[Instance.MONGODB_ARBITER,
Instance.REDIS_SENTINEL])
not_primary_hosts = [
instance.hostname for instance in not_primary_instances]
workflow_dict = build_dict(databaseinfra=databaseinfra,
database=database,
snapshot_id=snapshot_id,
export_path=export_path,
export_id=export_id,
host=host,
steps=steps,
not_primary_hosts=not_primary_hosts,
)
start_workflow(workflow_dict=workflow_dict, task=task_history)
if workflow_dict['exceptions']['traceback']:
error = "\n".join(
": ".join(err) for err in workflow_dict['exceptions']['error_codes'])
traceback = "\nException Traceback\n".join(
workflow_dict['exceptions']['traceback'])
error = "{}\n{}\n{}".format(error, traceback, error)
task_history.update_status_for(
TaskHistory.STATUS_ERROR, details=error)
else:
task_history.update_status_for(
TaskHistory.STATUS_SUCCESS, details='Database sucessfully recovered!')
return
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:56,代码来源:tasks.py
示例14: restore_database
def restore_database(self, database, task, snapshot, user, retry_from=None):
task = TaskHistory.register(
request=self.request, task_history=task, user=user,
worker_name=get_worker_name()
)
from backup.models import Snapshot
snapshot = Snapshot.objects.get(id=snapshot)
from tasks_restore_backup import restore_snapshot
restore_snapshot(database, snapshot.group, task, retry_from)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:11,代码来源:tasks.py
示例15: restore_snapshot
def restore_snapshot(self, request, database_id):
database = Database.objects.get(id=database_id)
url = reverse('admin:logical_database_change', args=[database.id])
if database.is_in_quarantine:
self.message_user(
request, "Database in quarantine and cannot be restored", level=messages.ERROR)
return HttpResponseRedirect(url)
if database.status != Database.ALIVE or not database.database_status.is_alive:
self.message_user(
request, "Database is dead and cannot be restored", level=messages.ERROR)
return HttpResponseRedirect(url)
if database.is_beeing_used_elsewhere():
self.message_user(
request, "Database is beeing used by another task, please check your tasks", level=messages.ERROR)
return HttpResponseRedirect(url)
if database.has_migration_started():
self.message_user(
request, "Database {} cannot be restored because it is beeing migrated.".format(database.name), level=messages.ERROR)
url = reverse('admin:logical_database_changelist')
return HttpResponseRedirect(url)
form = None
if request.method == 'POST':
form = RestoreDatabaseForm(
request.POST, initial={"database_id": database_id},)
if form.is_valid():
target_snapshot = request.POST.get('target_snapshot')
task_history = TaskHistory()
task_history.task_name = "restore_snapshot"
task_history.task_status = task_history.STATUS_WAITING
task_history.arguments = "Restoring {} to an older version.".format(
database.name)
task_history.user = request.user
task_history.save()
Database.recover_snapshot(database=database,
snapshot=target_snapshot,
user=request.user,
task_history=task_history.id)
url = reverse('admin:notification_taskhistory_changelist')
return HttpResponseRedirect(url + "?user=%s" % request.user.username)
else:
form = RestoreDatabaseForm(initial={"database_id": database_id, })
return render_to_response("logical/database/restore.html",
locals(),
context_instance=RequestContext(request))
开发者ID:jwestarb,项目名称:database-as-a-service,代码行数:55,代码来源:database.py
示例16: databaseregionmigration_view
def databaseregionmigration_view(self, request, databaseregionmigration_id):
form = DatabaseRegionMigrationDetailForm
database_region_migration = DatabaseRegionMigration.objects.get(
id=databaseregionmigration_id)
if request.method == 'POST':
form = DatabaseRegionMigrationDetailForm(request.POST)
if form.is_valid():
scheduled_for = form.cleaned_data['scheduled_for']
database_region_migration_detail = DatabaseRegionMigrationDetail(
database_region_migration=database_region_migration,
step=database_region_migration.current_step,
scheduled_for=scheduled_for,
created_by=request.user.username)
database_region_migration_detail.save()
task_history = TaskHistory()
task_history.task_name = "execute_database_region_migration"
task_history.task_status = task_history.STATUS_WAITING
description = database_region_migration.description()
task_history.arguments = "Database name: {},\
Macro step: {}".format(database_region_migration.database.name,
description)
task_history.user = request.user
task_history.save()
is_rollback = request.GET.get('rollback')
scheduled_for.replace(
tzinfo=tz.tzlocal()).astimezone(tz.tzutc())
if is_rollback:
LOG.info("Rollback!")
database_region_migration_detail.step -= 1
database_region_migration_detail.save()
task = execute_database_region_migration_undo.apply_async(args=[database_region_migration_detail.id,
task_history,
request.user],
eta=scheduled_for)
else:
task = execute_database_region_migration.apply_async(args=[database_region_migration_detail.id,
task_history, request.user],
eta=scheduled_for)
database_region_migration_detail.celery_task_id = task.task_id
database_region_migration_detail.save()
url = reverse('admin:notification_taskhistory_changelist')
return HttpResponseRedirect(url + "?user=%s" % request.user.username)
return render_to_response("region_migration/databaseregionmigrationdetail/schedule_next_step.html",
locals(),
context_instance=RequestContext(request))
开发者ID:hunterfu,项目名称:database-as-a-service,代码行数:55,代码来源:databaseregionmigration.py
示例17: create
def create(self, request):
serializer = self.get_serializer(data=request.DATA, files=request.FILES)
if serializer.is_valid():
self.pre_save(serializer.object)
data = serializer.restore_fields(request.DATA, request.FILES)
task_history = TaskHistory()
task_history.task_name="create_database"
task_history.task_status= task_history.STATUS_PENDING
task_history.arguments="Database name: {}".format(data['name'])
task_history.save()
result = create_database.delay(name=data['name'],
plan=data['plan'],
environment=data['environment'],
team=data['team'],
project=data['project'],
description=data['description'],
task_history=task_history,
user=request.user)
headers = self.get_success_headers(data)
task_url = Site.objects.get_current().domain + '/api/task?task_id=%s' % str(result.id)
return Response({"task":task_url}, status=status.HTTP_201_CREATED,
headers=headers)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:itnihao,项目名称:database-as-a-service,代码行数:31,代码来源:database.py
示例18: database_environment_migrate
def database_environment_migrate(
self, database, new_environment, new_offering, task, hosts_zones,
since_step=None, step_manager=None
):
task = TaskHistory.register(
request=self.request, task_history=task, user=task.user,
worker_name=get_worker_name()
)
from tasks_database_migrate import database_environment_migrate
database_environment_migrate(
database, new_environment, new_offering, task, hosts_zones, since_step,
step_manager=step_manager
)
开发者ID:globocom,项目名称:database-as-a-service,代码行数:13,代码来源:tasks.py
示例19: set_celery_healthcheck_last_update
def set_celery_healthcheck_last_update(self):
try:
worker_name = get_worker_name()
task_history = TaskHistory.register(request=self.request, user=None,
worker_name=worker_name)
LOG.info("Setting Celery healthcheck last update")
CeleryHealthCheck.set_last_update()
task_history.update_status_for(TaskHistory.STATUS_SUCCESS, details="Finished")
except Exception, e:
LOG.warn("Oopss...{}".format(e))
task_history.update_status_for(TaskHistory.STATUS_ERROR, details=e)
开发者ID:mbergo,项目名称:database-as-a-service,代码行数:13,代码来源:tasks.py
示例20: purge_unused_exports_task
def purge_unused_exports_task(self):
from notification.tasks import TaskRegister
task = TaskRegister.purge_unused_exports()
task = TaskHistory.register(
request=self.request, worker_name=get_worker_name(), task_history=task
)
task.add_detail('Getting all inactive exports without snapshots')
if purge_unused_exports(task):
task.set_status_success('Done')
else:
task.set_status_error('Error')
开发者ID:globocom,项目名称:database-as-a-service,代码行数:13,代码来源:tasks.py
注:本文中的notification.models.TaskHistory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论