-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Run queue tasks continuously #6062
Comments
The work-around is to bootstrap Drupal with each queue run, which isn't the worst, but I can put |
Cron as long running task sounds weird. Cron is meant for scheduled tasks. If you have a need to constantly process some large data, i.e. import products from external sources it's better to create a worker which could be an ordinary Drush command. Furthermore, even for scheduled custom tasks I would not mess with hook_cron but create a separate Drush command and put it to crontab like follows.
|
Ah that's right, I forget that modules can run tasks directly on cron run so maybe just having a long-running queue runner is actually what I want. |
@Chi-teck I updated the description, I hope this is helpful. it's honestly probably just an option on the existing command tbh |
I was tinkering with using (Advanced) Queue API for running server side commands. I thought there was a daemon! FWIW... This is how Aegir does it, with a Drush 8 command "hosting-queued": https://git.drupalcode.org/project/hosting/-/blob/7.x-3.x/queued/hosting_queued.drush.inc?ref_type=heads#L52-214 Would this be useful? https://github.com/mac-cain13/daemonizable-command Gonna look into this... |
I implemented something similar as a command some time ago. However, I don't currently use it. https://github.com/ueberbit/drush_queue_daemon |
Not sure if this module I've built some time ago could help https://www.drupal.org/project/recurring_task |
@webflo I liked your implementation, and I've tested it on my machine. If you don't mind explaining, why have you stopped to use that solution? |
@pierreabreup I no longer work for the client. But I think the code is still in use. I had no problems with it. I would use it again. |
I also built a lightweight (doesn't bootstrap Drupal unless necessary) queue runner that's currently running on multiple production sites: https://gist.github.com/DieterHolvoet/2ea792445f3498278e82221ab198288e |
@DieterHolvoet I suspect this eats 100% of CPU. while ($item = $queue->claimItem()) It needs some sleep on each iteration. |
Why's that? |
Never mind. It'll claims items unless the queue is empty. However, I think it'll not much better than |
Also restarting a process once a second could eat some resources. |
@DieterHolvoet why not just put |
To prevent memory leaks, or just memory piling up in general through e.g. static (entity) caches. Drupal so far isn't really optimized to be kept running for a long time, right? I'm not sure what is more performant, I'm also not saying my solution is the best one. All I can say is that it hasn't blown up any servers so far :) Would be interesting to compare the impact of different kinds of solutions. |
I would say it's pretty good with it. Typically, memory leaks because developers do not care about it. For instance, for static entity cache the |
To summarize PHP does not leak at all, at least in latest versions. Leaks mostly caused by custom code. However, small leaks like a few kB per day I would not even bother to debug. For the reference, a simple Drush command that does nothing consumes about 70 MB itself. Note that systemd is apparently does not have a way to gracefully restart a service when it exceed the configured memory limit. However, there are other process managers that do have have such an option. For instance, RoadRunner and Supervisord (via plugin). |
@DieterHolvoet that may happen with your current implementation as well. Memory does not leak when a process is idle. It will likely leak when it does something (i.e. |
Is your feature request related to a problem? Please describe.
We use Drupal's Queue feature to handle background tasks. However, many of these tasks are time sensitive and need to be executed in the background as soon as possible.
Drush doesn't provide a way to run a specific queue as a daemon, it can only be invoked on a schedule.
Describe the solution you'd like
I would really like a way to run Drupal queue as a long running task in the foreground. Then I can use systemd, docker, or k8s to keep it running.
Maybe a
queue:watch
command that is like:drush/src/Commands/core/QueueCommands.php
Lines 60 to 113 in 151b704
but that is running in an infinite loop (with a
usleep()
?) until the time limit or item limit is reached? Basically, it should keep running even if there are zero items in the queue right now.It might be nice to also limit the number of iterations by the amount of memory (i.e.
memory_get_usage()
) which would allow the script to be kept alive for as long as possible.Describe alternatives you've considered
drush queue:run
, but then we are doing the work to bootstrap Drupal and connect to the database on every iteration.Related:
Additional context
N/A
The text was updated successfully, but these errors were encountered: