Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outbox: Log progress #1407

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* Post meta to log Outbox processing progress in the Outbox post type API endpoint.

### Fixed

* Updates to certain user meta fields did not trigger an Update activity.
Expand Down
29 changes: 29 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,35 @@ private static function register_post_types() {
)
);

\register_post_meta(
Outbox::POST_TYPE,
'_activitypub_outbox_processing',
array(
'type' => 'object',
'single' => true,
'description' => 'Information about the processing of the outbox item.',
'show_in_rest' => array(
'schema' => array(
'type' => 'object',
'properties' => array(
'started' => array(
'type' => 'string',
),
'completed' => array(
'type' => 'string',
),
'total_inboxes' => array(
'type' => 'integer',
),
'error_count' => array(
'type' => 'integer',
),
),
),
),
)
);

// Both User and Blog Extra Fields types have the same args.
$args = array(
'labels' => array(
Expand Down
42 changes: 40 additions & 2 deletions includes/class-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ function ( $inboxes, $actor_id, $activity ) {
10,
3
);

\add_filter( 'activitypub_outbox_processing_complete', array( self::class, 'log_progress' ), 10, 7 );
\add_filter( 'activitypub_outbox_processing_batch_complete', array( self::class, 'log_progress' ), 10, 7 );
}

/**
Expand Down Expand Up @@ -142,10 +145,11 @@ public static function send_to_followers( $outbox_item_id, $batch_size = 50, $of
* @param string $json The ActivityPub Activity JSON
* @param int $actor_id The actor ID.
* @param int $outbox_item_id The Outbox item ID.
* @param array $retries The failed inboxes.
* @param int $batch_size The batch size.
* @param int $offset The offset.
*/
\do_action( 'activitypub_outbox_processing_complete', $inboxes, $json, $actor->get__id(), $outbox_item_id, $batch_size, $offset );
\do_action( 'activitypub_outbox_processing_complete', $inboxes, $json, $actor->get__id(), $outbox_item_id, $retries, $batch_size, $offset );

// No more followers to process for this update.
\wp_publish_post( $outbox_item_id );
Expand All @@ -159,10 +163,11 @@ public static function send_to_followers( $outbox_item_id, $batch_size = 50, $of
* @param string $json The ActivityPub Activity JSON
* @param int $actor_id The actor ID.
* @param int $outbox_item_id The Outbox item ID.
* @param array $retries The failed inboxes.
* @param int $batch_size The batch size.
* @param int $offset The offset.
*/
\do_action( 'activitypub_outbox_processing_batch_complete', $inboxes, $json, $actor->get__id(), $outbox_item_id, $batch_size, $offset );
\do_action( 'activitypub_outbox_processing_batch_complete', $inboxes, $json, $actor->get__id(), $outbox_item_id, $retries, $batch_size, $offset );

return array( $outbox_item_id, $batch_size, $offset + $batch_size );
}
Expand Down Expand Up @@ -355,6 +360,39 @@ public static function add_inboxes_of_replied_urls( $inboxes, $actor_id, $activi
return $inboxes;
}

/**
* Track progress of outbox processing.
*
* @param array $inboxes The inboxes.
* @param string $json The ActivityPub Activity JSON.
* @param int $actor_id The actor ID.
* @param int $outbox_item_id The Outbox item ID.
* @param array $retries The failed inboxes.
* @param int $batch_size The batch size.
* @param int $offset The offset.
*/
public static function log_progress( $inboxes, $json, $actor_id, $outbox_item_id, $retries, $batch_size, $offset ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move that to the debug class?

// Initialize processing data if this is the first batch.
if ( 0 === $offset ) {
$processing = array(
'started' => current_time( 'mysql' ),
'total_inboxes' => 0,
'error_count' => 0,
);
} else {
$processing = \get_post_meta( $outbox_item_id, '_activitypub_outbox_processing', true );
}

$processing['total_inboxes'] += count( $inboxes );
$processing['error_count'] += count( $retries );

if ( 'activitypub_outbox_processing_complete' === current_filter() ) {
$processing['completed'] = current_time( 'mysql' );
}

\update_post_meta( $outbox_item_id, '_activitypub_outbox_processing', $processing );
}

/**
* Adds Blog Actor inboxes to Updates so the Blog User's followers are notified of edits.
*
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Unreleased =

* Added: Post meta to log Outbox processing progress in the Outbox post type API endpoint.
* Fixed: Updates to certain user meta fields did not trigger an Update activity.

= 5.4.1 =
Expand Down
Loading