Problem/Motivation

I am currently using the Purge module with the HTTP purger to manage cached pages via cache tags on 3 varnish servers. Occasionally, one of the 3 servers needs to be taken offline for maintenance. During this time the purge module is correctly attempting to call the offline server and logging the invalidation requests as failed. This is causing performance issues because we are using the 'Late runtime processor'

Proposed resolution

The purge plugin configuration file does include a status settings (status: true) which does not do anything. Ideally, the UI should be provided a mechanism to disable/enable a purger.

Remaining tasks

TDB

User interface changes

TDB

API changes

TDB

Data model changes

None

CommentFileSizeAuthor
#10 alters.diff1.77 KBmoshe weitzman

Issue fork purge-2757155

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jrockowitz created an issue. See original summary.

nielsvm’s picture

I'm taking this into consideration. If and when I do accept this change, I'm unsure whether it will land in 8.x-3.0-beta5 or thereafter in 8.x-3.0-beta6.

moshe weitzman’s picture

Title: Provide a mechanism to disable a purger » Provide a mechanism to disable a purger and queuer

In addition to disabling a purger, I'd like to disable a queuer. My use is case is that during migrations, it makes no sense to queue items. There are thousands and thousands of new entries created. I would love a state variable that can be flipped off so that a config-import isn't needed to enable/disable a queuer temporarily.

nielsvm’s picture

I'm hearing you all...

And none of it is impossible, it just requires a thorough and consistent API-first approach since currently all purge's service classes have usage of the words "enable" and "disable" already (with the meaning of installing/uninstalling).

Although I know this isn't a full fix, check out the upcoming beta8 for these drush commands:

p-processor-add (pradd)  Add a new processor.
p-processor-ls  (prls)  List all enabled processors.
p-processor-lsa (prlsa)  List available processor plugin IDs that can be added.
p-processor-rm  (prrm)  Remove a processor.
...
p-purger-add (ppadd)  Create a new purger instance.
p-purger-ls (ppls)    List all configured purgers in order of execution.
p-purger-lsa (pplsa)  List available plugin IDs for which purgers can be added.
p-purger-mvd (ppmvd)  Move the given purger DOWN in the execution order.
p-purger-mvu (ppmvu)  Move the given purger UP in the execution order. 
p-purger-rm (pprm)    Remove a purger instance. 
...
p-queuer-add (puadd)  Add a new queuer.
p-queuer-ls (puls)    List all enabled queuers.
p-queuer-lsa (pulsa)  List available queuer plugin IDs that can be added.
p-queuer-rm (purm)    Remove a queuer.                                  

Hope those commands unblock you in the meanwhile, but I'll think about enabling/disabling.

falco010’s picture

I had a similar issue, I did not want to have the purger active on my local development.

In my settings.local.php I added this:

// Disable Varnish purging/logging on local.
$config['purge.plugins']['purgers'] = [];
$config['purge.logger_channels']['channels'] = [];

However the diagnostics service keeps logging errors now that I don't have an active purger :) But it is better then all the 1000 logs I got when it could not connect to Varnish from my local.

guptahemant’s picture

In one of our projects we wanted to pause purging during heavy operations(like migration, bulk updates) etc, so for that we implemented a config form with a checkbox and then added a custom diagnostic check implementation like this:

public function run() {
    if ($this->config->get('disable_purge') == TRUE) {
      $this->recommendation = $this->t('Purging is disabled.');
      return self::SEVERITY_ERROR;
    }

    $this->recommendation = $this->t('Purging is enabled.');
    return self::SEVERITY_OK;
  }

In above code we are utilising `self::SEVERITY_ERROR` to indicate to the diagnostics that purging can not happen which in turn pauses the purge activity. One thing to note though is that queuers and processors will still be triggering but they will be stopped before purge requests can fire.

firewaller’s picture

+1

guptahemant’s picture

Based on solution provided in #6, i have created a new contributed module: https://www.drupal.org/project/purge_control

moshe weitzman’s picture

StatusFileSize
new1.77 KB

Attached patch adds an alter hook for plugin definitions (purger, queue, queuer). This is common with plugins all around drupal.

With this patch, you can effectively disable a plugin by setting its 'types' to empty. That way it wont handle invalidations of type tag, url, everything, etc. Here is some example code:

/**
 * // Acquia Purger has no other way to disable, so we use plugin alter.
 *
 * @param $definitions
 * @return void
 *
 */
function mass_caching_purge_purgers_alter(&$definitions) {
  if (empty(getenv('AH_SITE_ENVIRONMENT'))) {
    // We are not in an Acquia env. Make their purgers capable of nothing.
    if (isset($definitions['acquia_purge'])) {
      // Note this can give a ValueError with PHP8. See https://www.drupal.org/project/purge/issues/3298855
       $definitions['acquia_purge']['types'] = [];
    }
  }
}

Please ignore the issue fork and just use the attached patch. I have to sort out an auth issue with gitlab.

moshe weitzman’s picture

Status: Active » Needs review
rodrigoaguilera’s picture

Assigned: jrockowitz » Unassigned

For reference:
The solution from #5 didn't work for me, only nulling each purger

$config['purge.plugins']['purgers'][0] = NULL;
$config['purge.plugins']['purgers'][1] = NULL;
$config['purge.plugins']['purgers'][2] = NULL;

  • japerry committed 57112485 on 8.x-3.x
    Issue #2757155 by japerry, moshe weitzman: Provide a mechanism to...
japerry’s picture

Status: Needs review » Fixed

Added a few more with the drush commands moving to purge core. Fixed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

clemorphy’s picture

I wish I had a more precise way than #12 to disable specific purgers.
Relying on indexes is not very safe as it could change when you add purgers or change their order.
There should be a boolean on each purger to define if it is enabled or not.
But for now #12 is my only working option.

pbouchereau’s picture

@japerry
How is this fixed?
What is the command to disable a queuer?
Per #4, the available solution "isn't a full fix".

pbouchereau’s picture

IMO there is no fix here, only workarounds and for a specific use case on top of that.
The commit retitles the issue to "provide a mechanism to programatically alter purge plugins" which has a substantially different meaning.
The altering doesn't help me as I don't have steady cases where the queuer should be active or inactive.
I have a nightly migration so the queuer has to be deactivated before and activated after.
Correct me if I'm wrong, but if I used the "p-queuer-rm" and "p-queuer-add" commands I'd still have to configure the queuer.
For that I'd have to do a config import which I'd like to avoid.
A simple "drush p:queuer-off 2fb86f01dc" would be so nice... do you think it's conceivable?

guptahemant’s picture

@pbouchereau In #8 i created a new contrib module, check if that helps

pbouchereau’s picture

Thanks @guptahemant but if I got it right your module doesn't prevent queueing to happen, which is what I want.

pbouchereau’s picture

Title: Provide a mechanism to disable a purger and queuer » Provide a mechanism to programatically alter purge plugins

Since I can't change the status to "closed (won't fix)" I change the title to what was actually fixed.