+ 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 ) {
+ if ( $update instanceof DataUpdate ) {
+ $update->setTransactionTicket( $lbFactory->getEmptyTransactionTicket( __METHOD__ ) );
+ }
+
+ if (
+ $update instanceof TransactionRoundAwareUpdate &&
+ $update->getTransactionRoundRequirement() == $update::TRX_ROUND_ABSENT
+ ) {
+ $fnameTrxOwner = null;
+ } else {
+ $fnameTrxOwner = get_class( $update ) . '::doUpdate';
+ }
+
+ if ( $fnameTrxOwner !== null ) {
+ $lbFactory->beginMasterChanges( $fnameTrxOwner );
+ }
+
+ $update->doUpdate();
+
+ if ( $fnameTrxOwner !== null ) {
+ $lbFactory->commitMasterChanges( $fnameTrxOwner );
+ }