Making WordPress.org

Changeset 5131


Ignore:
Timestamp:
03/08/2017 07:31:45 PM (10 years ago)
Author:
iandunn
Message:

Official WordPress Events: Add more logging to troubleshoot cron bug

After r5017, the jobs ran successfully for a week. When I removed the unintentional wp_die() in r5112, the jobs started getting stuck again. The log shows it getting stuck in the get_meetup_group_ids() and get_meetup_events() loops, so I'm adding more logging here to get insight into that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r5112 r5131  
    418418
    419419                        while ( '' !== $request_url ) {
     420                                $this->log( 'fetching more events from: ' . var_export( $request_url, true ) );
     421
    420422                                $response = $this->remote_get( $request_url );
    421423                                $body     = json_decode( wp_remote_retrieve_body( $response ) );
    422424
    423                                 $this->log( 'fetching more events' );
     425                                $this->log( 'pruned response - ' . print_r( $this->prune_response_for_log( $response ), true ) );
    424426
    425427                                if ( ! empty ( $body->results ) ) {
    … …  
    498500
    499501                while ( '' !== $request_url ) {
    500                         $this->log( 'fetching more groups' );
     502                        $this->log( 'fetching more groups from: ' . var_export( $request_url, true ) );
    501503
    502504                        $response = $this->remote_get( $request_url );
    503505                        $body     = json_decode( wp_remote_retrieve_body( $response ) );
     506
     507                        $this->log( 'pruned response - ' . print_r( $this->prune_response_for_log( $response ), true ) );
    504508
    505509                        if ( ! empty ( $body->results ) ) {
    … …  
    689693         * To avoid storing too much data, the log is reset during each run, and only $limit rows are stored
    690694         *
     695         * @todo Remove this when the stuck cron job bug is fixed
     696         *
    691697         * @param string $message
    692698         */
    … …  
    718724                update_option( 'owpe_log', $this->log, false );
    719725        }
     726
     727        /**
     728         * Prune an HTTP response so the relevant data can be logged for troubleshooting
     729         *
     730         * @todo Remove this when the stuck cron job bug is fixed
     731         *
     732         * @param WP_HTTP_Response $response
     733         *
     734         * @return array
     735         */
     736        protected function prune_response_for_log( $response ) {
     737                $pruned_response = (array) $response;
     738
     739                if ( isset( $pruned_response['body'] ) ) {
     740                        $pruned_response['original_body_meta'] = sprintf(
     741                                'type: %s / length: %s',
     742                                gettype( $pruned_response['body'] ),
     743                                is_string( $pruned_response['body'] ) ? strlen( $pruned_response['body'] ) : 'not a string'
     744                        );
     745                        $pruned_response['body'] = (array) json_decode( $pruned_response['body'] );
     746
     747                        if ( isset( $pruned_response['body']['results'] ) ) {
     748                                $pruned_response['body']['results'] = 'pruned';
     749                        }
     750                }
     751
     752                if ( isset( $pruned_response['http_response'] ) ) {
     753                        unset( $pruned_response['http_response'] );
     754                }
     755
     756                if ( isset( $pruned_response['cookies'] ) ) {
     757                        unset( $pruned_response['cookies'] );
     758                }
     759
     760                if ( isset( $pruned_response['filename'] ) ) {
     761                        unset( $pruned_response['filename'] );
     762                }
     763
     764                return $pruned_response;
     765        }
    720766}
    721767
Note: See TracChangeset for help on using the changeset viewer.