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

Change remote-controlled features request to be cron-based #4856

Closed
felixarntz opened this issue Feb 16, 2022 · 2 comments
Closed

Change remote-controlled features request to be cron-based #4856

felixarntz opened this issue Feb 16, 2022 · 2 comments
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature

Comments

@felixarntz
Copy link
Member

felixarntz commented Feb 16, 2022

In order to run the /site-management/features/ request more regularly, it should be changed to be primarily invoked in a (WP) cron-job. Only if for whatever reason no data is set yet (e.g. right after connecting to the service), the request should be issued on demand.

This is part of a set of 2 issues (and related service enhancements) to make the check more flexible and provide additional criteria for whether to enable a feature or not.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The request to retrieve the remote-controlled active features should be changed to be invoked in a WordPress cron job, running twicedaily.
  • While that should be the new "default", the request should still be invoked on demand if no data is set yet for the remote-controlled features.
    • In other words, the current Authentication::filter_features_via_proxy method can probably remain as is - it will most likely not invoke the request though since the data in most situations will already have been populated via the cron hook.
  • Similar to now, the request should in any case only be issued if the site is already connected to the service, i.e. has its site credentials.

Implementation Brief

Within includes/Core/Authentication/Authentication.php:

  • Extract the following block from filter_features_via_proxy into a new function, called e.g. get_transient_features.
    $features = $this->transients->get( $transient_name );
    if ( false === $features ) {
    $features = $this->google_proxy->get_features( $this->credentials );
    if ( is_wp_error( $features ) ) {
    $this->transients->set( $transient_name, array(), HOUR_IN_SECONDS );
    } else {
    $this->transients->set( $transient_name, $features, DAY_IN_SECONDS );
    // Update persistent option for 'serviceSetupV2'.
    if ( isset( $features['serviceSetupV2']['enabled'] ) ) {
    $this->options->set( $service_setup_v2_option_name, (bool) $features['serviceSetupV2']['enabled'] );
    }
    }
    }
  • In the register method, use the wp_schedule_event WP API function to schedule a twicedaily call to get_transient_features.

Test Coverage

  • Add PHPUnit test coverage for the new functionality.

QA Brief

Changelog entry

  • Change remote-controlled features request to be cron-based, running twice daily.
@felixarntz felixarntz added P0 High priority Type: Enhancement Improvement of an existing feature QA: Eng Requires specialized QA by an engineer labels Feb 16, 2022
@felixarntz felixarntz self-assigned this Feb 16, 2022
@felixarntz felixarntz removed their assignment Feb 16, 2022
@techanvil techanvil assigned techanvil and unassigned techanvil Feb 21, 2022
@tofumatt tofumatt self-assigned this Feb 24, 2022
@tofumatt
Copy link
Collaborator

IB ✅

@tofumatt tofumatt removed their assignment Feb 24, 2022
@jimmymadon jimmymadon self-assigned this Mar 6, 2022
@jimmymadon jimmymadon removed their assignment Mar 7, 2022
@techanvil techanvil assigned techanvil and unassigned techanvil Mar 7, 2022
@hussain-t hussain-t self-assigned this Mar 8, 2022
@hussain-t
Copy link
Collaborator

QA Verified ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants