Add a finish event for static HTML generator batch

Created on 22 December 2020, almost 4 years ago
Updated 13 March 2024, 8 months ago

It will be helpful to have an event when the static HTML generator has finished.

Feature request
Status

Needs work

Version

1.0

Component

Tome Static

Created by

🇷🇴Romania aalin

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Status changed to Needs work 10 months ago
  • 🇬🇧United Kingdom joachim

    Setting to NW based on #8.

    Making a MR for this and going to address some of the points.

  • 🇬🇧United Kingdom joachim

    > we also generate static HTML via the command line and tome_static_cron,

    This to me really suggests that more of the static generation code should be in an API and less in the running/UI code -- Drush/cron/batch. But that's for another issue.

    I can add the success event to the Drush StaticCommand class, but I'm not sure where the failure event would get called? There's this in exportPaths():

        if (!empty($collected_errors)) {
          $this->displayErrors($collected_errors);
        }
    

    but exportPaths is called recursively in StaticCommand AND by the inner command StaticExportPathCommand -- so the event would be fired multiple times which we don't want. (See 📌 refactor code to remove Drush command calling another command Active .)

    For cron it's even worse -- I'm not suere where we'd call the success event, as things are put into a queue. I guess we could add a final queue item whose sole purpose is to fire the event?

  • Merge request !15Draft: #3189525 "Add finish event" → (Open) created by joachim
  • 🇬🇧United Kingdom joachim

    I think the success/failure distinction needs more thought.

    This code in the StaticGeneratorForm (in the MR version) shows this:

        if (!$success) {
          # This is a failure of the whole batch with Batch API.
          $this->messenger()->addError($this->t('Static build failed - consult the error log for more details.'));
          $event = new BuildFinishEvent(FALSE);
          $this->eventDispatcher->dispatch($event, TomeStaticEvents::BUILD_FINISH);
          return;
        }
        if (!empty($results['errors'])) {
          # This is exceptions from making requests with StaticGenerator.
          # This counts as a success!
          foreach ($results['errors'] as $error) {
            $this->messenger()->addError($error);
          }
        }
    

    We have batch API failure, but also a case where we have error messages from StaticGenerator - but that's treated as a success.

    And furthermore, error messages from StaticGenerator do NOT include errors if requests for site paths produce a 500 from the site -- those errors are just ignored -- see StaticGenerator::requestPath() doesn't do anything with a request that produces a 500 error Needs review .

  • 🇧🇪Belgium yoerioptr

    I've updated the patch so it applies again. Also triggered the event after executing the tome:static command.

Production build 0.71.5 2024