Module: AfterCommitQueue
- Extended by:
- ActiveSupport::Concern
- Included in:
- AntiAbuse::Reports::Note, AsyncDeviseEmail, AuditEvent, BulkImport, BulkImports::Entity, BulkImports::Tracker, Ci::Bridge, Ci::Build, Ci::JobArtifact, Ci::Pipeline, Ci::Ref, Clusters::Cluster, Clusters::Integrations::Prometheus, Clusters::Platforms::Kubernetes, CommitStatus, ContainerRepository, CounterAttribute, Deployment, DesignManagement::Version, FastDestroyAll::Helpers, Group, Issuable, JiraImportState, Key, LfsObject, Member, Milestone, Namespace, Namespace::AggregationSchedule, NamespaceStatistics, Note, Operations::FeatureFlag, Packages::PackageFile, PagesDomain, PoolRepository, Project, ProjectExportJob, ProjectGroupLink, ProjectImportState, Projects::BuildArtifactsSizeRefresh, RemoteMirror, RepositoryStorageMovable, Snippet, SnippetStatistics, Terraform::State, UpdateNamespaceStatistics, UpdateProjectStatistics, User, X509Certificate
- Defined in:
- app/models/concerns/after_commit_queue.rb
Instance Method Summary collapse
- #run_after_commit(&block) ⇒ Object
-
#run_after_commit_or_now(&block) ⇒ Object
When within a database transaction, execute the given block after the transaction is committed.
Instance Method Details
#run_after_commit(&block) ⇒ Object
11 12 13 14 15 |
# File 'app/models/concerns/after_commit_queue.rb', line 11 def run_after_commit(&block) _after_commit_queue << block if block true end |
#run_after_commit_or_now(&block) ⇒ Object
When within a database transaction, execute the given block after the transaction is committed. Otherwise execute the given block ATTENTION: because this uses ‘instance_eval` to evaluate the block, instance variables within the block will be evaluated based on the object on which `run_after_commit_or_now` gets executed. gitlab.com/gitlab-org/gitlab/-/merge_requests/146208#note_1800349073
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/concerns/after_commit_queue.rb', line 22 def run_after_commit_or_now(&block) if self.class.inside_transaction? if connection.current_transaction.records&.include?(self) run_after_commit(&block) else # If the current transaction does not include this record, we can run # the block now, even if it queues a Sidekiq job. Sidekiq::Worker.skipping_transaction_check do instance_eval(&block) end end else instance_eval(&block) end true end |