当前位置: 首页>>代码示例>>Python>>正文


Python transaction.on_commit方法代码示例

本文整理汇总了Python中django.db.transaction.on_commit方法的典型用法代码示例。如果您正苦于以下问题:Python transaction.on_commit方法的具体用法?Python transaction.on_commit怎么用?Python transaction.on_commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.transaction的用法示例。


在下文中一共展示了transaction.on_commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: async_register

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def async_register(self, registration_id, logger_context=None):
    self.setup_logger(logger_context)

    self.registration = Registration.objects.get(id=registration_id)
    try:
        with transaction.atomic():
            self.registration.event.register(self.registration)
            transaction.on_commit(
                lambda: notify_event_registration(
                    constants.SOCKET_REGISTRATION_SUCCESS, self.registration
                )
            )
        log.info("registration_success", registration_id=self.registration.id)
    except EventHasClosed as e:
        log.warn(
            "registration_tried_after_started",
            exception=e,
            registration_id=self.registration.id,
        )
    except (ValueError, IntegrityError) as e:
        log.error(
            "registration_error", exception=e, registration_id=self.registration.id
        )
        raise self.retry(exc=e, max_retries=3) 
开发者ID:webkom,项目名称:lego,代码行数:26,代码来源:tasks.py

示例2: form_valid

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def form_valid(self, form):
        existing_kext_policies = (KernelExtensionPolicy.objects.select_for_update()
                                                               .filter(meta_business_unit=self.meta_business_unit))
        # there should be at most a trashed one.
        try:
            instance = existing_kext_policies[0]
        except IndexError:
            pass
        else:
            form.instance = instance
        kext_policy = form.save(commit=False)
        kext_policy.meta_business_unit = self.meta_business_unit
        kext_policy.trashed_at = None
        kext_policy.save()
        form.save_m2m()
        transaction.on_commit(lambda: send_mbu_enrolled_devices_notifications(kext_policy.meta_business_unit))
        return HttpResponseRedirect(kext_policy.get_absolute_url()) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:19,代码来源:management.py

示例3: save

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def save(self, *args, **kwargs):
        # whether the job is being created for the first time
        first_save = self.pk is None
        # resetting expired_date in case a user resets the end_date
        if self.expired_date and self.end_date and self.end_date > timezone.now():
            self.expired_date = None
        super().save(*args, **kwargs)
        # Remove the cached latest run to this objects will requery it.
        try:
            delattr(self, "latest_run")
        except AttributeError:  # pragma: no cover
            pass  # It didn't have a `latest_run` and that's ok.
        # first remove if it exists
        self.schedule.delete()
        # and then add it, but only if the end date is in the future
        if self.has_future_end_date(timezone.now()):
            self.schedule.add()
        if first_save:
            transaction.on_commit(self.first_run) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:21,代码来源:models.py

示例4: provision_run

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def provision_run(self, spark_job, first_run=False):
        """
        Actually run the given Spark job.

        If this is the first run we'll update the "last_run_at" value
        to the start date of the spark_job so Celery beat knows what's
        going on.
        """
        spark_job.run()
        if first_run:

            def update_last_run_at():
                schedule_entry = spark_job.schedule.get()
                if schedule_entry is None:
                    schedule_entry = spark_job.schedule.add()
                schedule_entry.reschedule(last_run_at=spark_job.start_date)

            transaction.on_commit(update_last_run_at) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:20,代码来源:tasks.py

示例5: model_post_save

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def model_post_save(sender, instance, created=False, **kwargs):
    """Signal emitted after any model is saved via Django ORM.

    :param sender: Model class that was saved
    :param instance: The actual instance that was saved
    :param created: True if a new row was created
    """

    if sender._meta.app_label == 'rest_framework_reactive':
        # Ignore own events.
        return

    def notify():
        table = sender._meta.db_table
        if created:
            notify_observers(table, ORM_NOTIFY_KIND_CREATE, instance.pk)
        else:
            notify_observers(table, ORM_NOTIFY_KIND_UPDATE, instance.pk)

    transaction.on_commit(notify) 
开发者ID:genialis,项目名称:django-rest-framework-reactive,代码行数:22,代码来源:signals.py

示例6: model_post_delete

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def model_post_delete(sender, instance, **kwargs):
    """Signal emitted after any model is deleted via Django ORM.

    :param sender: Model class that was deleted
    :param instance: The actual instance that was removed
    """

    if sender._meta.app_label == 'rest_framework_reactive':
        # Ignore own events.
        return

    def notify():
        table = sender._meta.db_table
        notify_observers(table, ORM_NOTIFY_KIND_DELETE, instance.pk)

    transaction.on_commit(notify) 
开发者ID:genialis,项目名称:django-rest-framework-reactive,代码行数:18,代码来源:signals.py

示例7: model_m2m_changed

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def model_m2m_changed(sender, instance, action, **kwargs):
    """
    Signal emitted after any M2M relation changes via Django ORM.

    :param sender: M2M intermediate model
    :param instance: The actual instance that was saved
    :param action: M2M action
    """

    if sender._meta.app_label == 'rest_framework_reactive':
        # Ignore own events.
        return

    def notify():
        table = sender._meta.db_table
        if action == 'post_add':
            notify_observers(table, ORM_NOTIFY_KIND_CREATE)
        elif action in ('post_remove', 'post_clear'):
            notify_observers(table, ORM_NOTIFY_KIND_DELETE)

    transaction.on_commit(notify) 
开发者ID:genialis,项目名称:django-rest-framework-reactive,代码行数:23,代码来源:signals.py

示例8: forms_valid

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def forms_valid(self, secret_form, enrollment_form):
        # make secret
        secret = secret_form.save()
        # make enrollment
        enrollment = enrollment_form.save(commit=False)
        enrollment.version = 0
        enrollment.secret = secret
        enrollment.save()
        enrollment_form.save_m2m()
        # MDM enrollment package
        mep = MDMEnrollmentPackage.objects.create(
            meta_business_unit=secret.meta_business_unit,
            builder=self.builder_key,
            enrollment_pk=enrollment.pk
        )
        # link from enrollment to mdm enrollment package, for config update propagation
        enrollment.distributor = mep
        enrollment.save()  # build package and package manifest via callback call
        transaction.on_commit(lambda: send_mbu_enrolled_devices_notifications(mep.meta_business_unit))
        return HttpResponseRedirect(mep.get_absolute_url()) 
开发者ID:zentralopensource,项目名称:zentral,代码行数:22,代码来源:management.py

示例9: destroy_instance

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def destroy_instance(sender,instance,**kwargs):
    #to aviold repeated deletion
    for instance in sender.objects.select_for_update().filter(pk=instance.pk):
        def destroy():
            if not instance.ready:
                print('WARNNING: delete instance under building')
            else:
                try:
                    instance.cloud.driver.instances.force_delete(str(instance.uuid))
                except Exception as e:#TODO may spam the log
                    instance.pk=None
                    instance.save()
                    traceback.print_exc()
                    return
            destroyed.send(sender=sender, instance=instance, name='destroyed')
        transaction.on_commit(Thread(target=destroy).start) 
开发者ID:cas-packone,项目名称:packone,代码行数:18,代码来源:signals.py

示例10: materialize_volume

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def materialize_volume(sender, instance, **kwargs):
    if not kwargs['created'] or instance.ready: return
    instance.built_time=now()
    instance.save()
    @transaction.atomic
    def materialize(volume=instance):
        volume=sender.objects.select_for_update().get(pk=volume.pk)
        remark = settings.PACKONE_LABEL+'.'+volume.cloud.name+';'
        if volume.remark: remark+=volume.remark
        info=volume.cloud.driver.volumes.create(
            volume.capacity,
            remark=remark
        )
        volume.uuid=UUID(info.id.replace('-', ''), version=4)
        volume.built_time=now()
        volume.status=VOLUME_STATUS.available.value
        volume.save()
        materialized.send(sender=sender, instance=volume, name='materialized')
    transaction.on_commit(Thread(target=materialize).start) 
开发者ID:cas-packone,项目名称:packone,代码行数:21,代码来源:signals.py

示例11: destroy_volume

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def destroy_volume(sender,instance,**kwargs):
    #to aviold repeated deletion
    for volume in sender.objects.select_for_update().filter(pk=instance.pk):
        def destroy():
            if not volume.ready:
                print('WARNNING: delete volume under building')
            else:
                try:
                    volume.cloud.driver.volumes.delete(
                        str(volume.uuid)
                    )
                except Exception as e:#TODO may spam the log
                    volume.pk=None
                    volume.save()
                    traceback.print_exc()
                    return
            destroyed.send(sender=sender, instance=volume, name='destroyed')
        transaction.on_commit(Thread(target=destroy).start) 
开发者ID:cas-packone,项目名称:packone,代码行数:20,代码来源:signals.py

示例12: umount

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def umount(sender,instance,**kwargs):
    #to aviold repeated deletion
    for mount in sender.objects.select_for_update().filter(pk=instance.pk):
        @transaction.atomic
        def destroy(mount=mount):
            volume=Volume.objects.select_for_update().get(pk=mount.volume.pk)
            if not mount.ready:
                print('WARNNING: delete mount under building')
            else:
                try:
                    mount.volume.cloud.driver.volumes.unmount(
                        str(mount.volume.uuid),
                        str(mount.instance.uuid)
                    )
                except Exception as e:
                    mount.pk=None
                    mount.save()
                    traceback.print_exc()
                    return
                volume.status=VOLUME_STATUS.available.value
                volume.save()
                mount.instance.update_remedy_script(utils.remedy_script_mount_remove(mount))
            destroyed.send(sender=sender, instance=mount, name='destroyed')
        transaction.on_commit(Thread(target=destroy).start) 
开发者ID:cas-packone,项目名称:packone,代码行数:26,代码来源:signals.py

示例13: manager_post_save_handler

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def manager_post_save_handler(sender, instance, created, **kwargs):
    """Run newly created (spawned) processes."""
    if (
        instance.status == Data.STATUS_DONE
        or instance.status == Data.STATUS_ERROR
        or created
    ):
        # Run manager at the end of the potential transaction. Otherwise
        # tasks are send to workers before transaction ends and therefore
        # workers cannot access objects created inside transaction.
        transaction.on_commit(lambda: commit_signal(instance.id))


# NOTE: m2m_changed signal cannot be used because of a bug:
# https://code.djangoproject.com/ticket/17688 
开发者ID:genialis,项目名称:resolwe,代码行数:17,代码来源:signals.py

示例14: delete_relation

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def delete_relation(sender, instance, **kwargs):
    """Delete the Relation object when the last Entity is removed."""

    def process_signal(relation_id):
        """Get the relation and delete it if it has no entities left."""
        try:
            relation = Relation.objects.get(pk=relation_id)
        except Relation.DoesNotExist:
            return

        if relation.entities.count() == 0:
            relation.delete()

    # Wait for partitions to be recreated.
    transaction.on_commit(lambda: process_signal(instance.relation_id)) 
开发者ID:genialis,项目名称:resolwe,代码行数:17,代码来源:signals.py

示例15: save

# 需要导入模块: from django.db import transaction [as 别名]
# 或者: from django.db.transaction import on_commit [as 别名]
def save(self, *args, **kwargs):
        """Save instance and start data ingest task for active Provider."""

        should_ingest = False
        # These values determine if a Provider is new
        if self.created_timestamp and not self.setup_complete:
            should_ingest = True

        try:
            provider = Provider.objects.get(uuid=self.uuid)
        except Provider.DoesNotExist:
            pass
        else:
            # These values determine if Provider credentials have been updated:
            if provider.authentication != self.authentication or provider.billing_source != self.billing_source:
                should_ingest = True

        # Commit the new/updated Provider to the DB
        super().save(*args, **kwargs)

        if settings.AUTO_DATA_INGEST and should_ingest and self.active:
            # Local import of task function to avoid potential import cycle.
            from masu.celery.tasks import check_report_updates

            LOG.info(f"Starting data ingest task for Provider {self.uuid}")
            # Start check_report_updates task after Provider has been committed.
            transaction.on_commit(lambda: check_report_updates.delay(provider_uuid=self.uuid)) 
开发者ID:project-koku,项目名称:koku,代码行数:29,代码来源:models.py


注:本文中的django.db.transaction.on_commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。