當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。