How can I render a page template from a queue job/console controller? I'm trying to call craft\web\View::renderPageTemplate from within a console controller (also tried from a queue job), but running into all kinds of trouble:

E.g.


Exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("Session does not exist in a console request.").'


I discovered the this was due to registerAssetFlashes: https://github.com/craftcms/cms/blob/279116ba4091edc67c92fcbbefc257bb4fe30335/src/web/View.php#L1418

No plugins that register twig functions/filters work


Currently I'm doing:

$view = Craft::$app-&gt;getView();
$view-&gt;setTemplateMode($view::TEMPLATE_MODE_SITE);
$view-&gt;renderPageTemplate($template, $variables);


The end goal is to render a template, cache it, and send the html to a web service.

How can I do this without everything breaking?

…Or is there another way to do this, or should this be a feature request?
Given that it's craft\web\View.php I think you're probably out of luck. Though it's only registerAssetFlashes() that seems to call getSession(), but I'm expecting more than just that may assume a frontend request. You could always ping a controller endpoint via Guzzle to return the Twig-rendered HTML to you though.