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

Slow generation via queue #162

Open
Diewy opened this issue Mar 8, 2024 · 0 comments
Open

Slow generation via queue #162

Diewy opened this issue Mar 8, 2024 · 0 comments

Comments

@Diewy
Copy link

Diewy commented Mar 8, 2024

Hi all,

I'm working on a website with multiple editors, aiming for high scalability. We're using Statamic along with this package to generate the static site and serve it via S3. It works beautifully, is highly secure, and scalable. However, there's a caveat: the developers have to run the command php please ssg:generate to publish changes, which cannot be executed by a site editor.

So, I'm in the process of creating a utility to allow site editors to initiate the static site generation. Since the generation process takes approximately 15 seconds, I'd like to trigger a queued job when a site editor clicks a button.

However, when handling the job with Horizon or using the database as the queue driver, the generation process takes over 45 minutes. When the queue driver is set to sync, it only takes around 15 seconds again.

I've attempted to debug the issue, and it seems like the delay is occurring at Page.php:58. However, I'm unsure where to proceed from here.

The job:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Statamic\StaticSite\Generator;

class StaticSiteGenerate implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    /**
     * The number of seconds the job can run before timing out.
     *
     * @var int
     */
    public $timeout = 300;

    /**
     * @var Generator
     */
    protected $generator;

    /**
     * @var int
     */
    protected $workers = 2;

    public function handle(Generator $generator): void
    {
        $generator
            ->workers($this->workers)
            ->generate('*');
    }
}

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants