TC
Twill CMS7mo ago
bora

Order and nesting not working

I installed twill using the php artisan twill:install basic-page-builder command. Seems that ordering and nesting is not working on the navigation.
10 Replies
bora
boraOP7mo ago
Turns out twill uses ReorderNestedModuleItems job for nesting and my QUEUE_CONNECTION is database. Just needed to do php artisan queue:work
Adam Mateusz Brożyński
So basicaly reordering items is impossible without cron job executing queue? Is there a way to have working sortable items without need to have access to cron? I've found a solution how to manage it when no access to cron: web.php Route::get('/jobs/run', function() { Artisan::call('queue:work', ['--stop-when-empty' => true]); }); resources/vendor/twill/partials/head.blade.php (add to <script>): <script src="/jobs.js" defer></script> public/jobs.js:
async function runJob() { fetch('/jobs/run'); }
runJob();
async function runJob() { fetch('/jobs/run'); }
runJob();
This will do the trick for small websites. This fetch can also be put on frontend to have cronless queue, but it's better to have PHP function that will control frequency, so it won't be executed on every single frontend site visit. Also it would be a good idea to make a check if jobs/run is executed from within site. Even better solution in PHP that runs in background (needs exec available and php-cli on server):
$cmd = 'cd '.base_path().' && /usr/bin/php artisan queue:work --stop-when-empty';
$out = base_path().'/queue.log';
$pid = base_path().'/queue.pid';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $out, $pid));
$cmd = 'cd '.base_path().' && /usr/bin/php artisan queue:work --stop-when-empty';
$out = base_path().'/queue.log';
$pid = base_path().'/queue.pid';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $out, $pid));
If we want to use it in frontent we can add things like: - lock file and lock file check - timestamp check (we can do it using database or just filemtime) to control execution rate
ifox
ifox5mo ago
Or, for small page trees, you can use Laravel's sync queue driver
Adam Mateusz Brożyński
But is it running in the background or blocking request until jobs are done?
ifox
ifox5mo ago
yes, but it's really fast on a small page tree. also this only applies to self nested modules. A regular module with reordering enabled doesn't require a job.
Adam Mateusz Brożyński
I understand, but I think most websites use at least second level nesting. Also if it's possible to do it by middleware and in background without any slowdown it seems to do be a quite good solution also for big websites, because it actually does what cron does. I will share full code when it's finished.
ifox
ifox5mo ago
be mindful that at scale the operations need to happen sequentially, otherwise you're going to end up with a broken tree
ifox
ifox5mo ago
GitHub
GitHub - lazychaser/laravel-nestedset: Effective tree structures in...
Effective tree structures in Laravel 4-8. Contribute to lazychaser/laravel-nestedset development by creating an account on GitHub.
ifox
ifox5mo ago
yes, most websites do, but not necessarily with self nested modules. we have built a ton of very large websites without using it
Adam Mateusz Brożyński
I've finished my middleware. Code below does nothing more than artisan queue:work --stop-when-empty and really not more that only once in the minimum given time span of seconds (flock does the trick) and really in the background (command is daemonized) so there is no slowdowns while browsing. Let me know if you think this has some flaws: https://dev.to/ordigital/cronless-queuework-in-laravel-executed-in-background-2n01
DEV Community
Cronless queue:work in Laravel executed in background
There are some approaches how to execute queue:work but I found them useless. Here is a solution for...
Want results from more Discord servers?
Add your server