+ return $e;
+ }
+
+ /**
+ * Push a task into the job queue system and catch/log any exceptions
+ *
+ * @param EnqueueableDataUpdate $update
+ * @param LBFactory $lbFactory
+ * @param LoggerInterface $logger
+ * @param StatsdDataFactoryInterface $stats
+ * @param string $httpMethod
+ */
+ private static function jobify(
+ EnqueueableDataUpdate $update,
+ LBFactory $lbFactory,
+ LoggerInterface $logger,
+ StatsdDataFactoryInterface $stats,
+ $httpMethod
+ ) {
+ $stats->increment( "deferred_updates.$httpMethod." . get_class( $update ) );
+
+ $e = null;
+ try {
+ $spec = $update->getAsJobSpecification();
+ JobQueueGroup::singleton( $spec['domain'] ?? $spec['wiki'] )->push( $spec['job'] );
+ } catch ( Exception $e ) {
+ } catch ( Throwable $e ) {
+ }
+
+ if ( $e ) {
+ $logger->error(
+ "Job insertion of deferred update {type} failed: {message}",
+ [
+ 'type' => get_class( $update ),
+ 'message' => $e->getMessage(),
+ 'trace' => $e->getTraceAsString()
+ ]
+ );
+ $lbFactory->rollbackMasterChanges( __METHOD__ );
+ }
+ }
+
+ /**
+ * Attempt to run an update with the appropriate transaction round state it expects
+ *
+ * DeferredUpdate classes that wrap the execution of bundles of other DeferredUpdate
+ * instances can use this method to run the updates. Any such wrapper class should
+ * always use TRX_ROUND_ABSENT itself.
+ *
+ * @param DeferrableUpdate $update
+ * @param ILBFactory $lbFactory
+ * @since 1.34
+ */
+ public static function attemptUpdate( DeferrableUpdate $update, ILBFactory $lbFactory ) {
+ $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
+ if ( !$ticket || $lbFactory->hasTransactionRound() ) {
+ throw new DBTransactionError( null, "A database transaction round is pending." );
+ }
+
+ if ( $update instanceof DataUpdate ) {
+ $update->setTransactionTicket( $ticket );
+ }
+
+ $fnameTrxOwner = get_class( $update ) . '::doUpdate';
+ $useExplicitTrxRound = !(
+ $update instanceof TransactionRoundAwareUpdate &&
+ $update->getTransactionRoundRequirement() == $update::TRX_ROUND_ABSENT
+ );
+ // Flush any pending changes left over from an implicit transaction round
+ if ( $useExplicitTrxRound ) {
+ $lbFactory->beginMasterChanges( $fnameTrxOwner ); // new explicit round
+ } else {
+ $lbFactory->commitMasterChanges( $fnameTrxOwner ); // new implicit round
+ }
+ // Run the update after any stale master view snapshots have been flushed
+ $update->doUpdate();
+ // Commit any pending changes from the explicit or implicit transaction round
+ $lbFactory->commitMasterChanges( $fnameTrxOwner );