本文整理汇总了Python中notification.models.TaskHistory类的典型用法代码示例。如果您正苦于以下问题:Python TaskHistory类的具体用法?Python TaskHistory怎么用?Python TaskHistory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskHistory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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()
示例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)
示例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
示例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)
示例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))