Skip to main content
13 votes

How can execute batch api over cron jobs

You don't. Batch API is to do long-running processing with user-interaction. For cron, you either use Queue API or you just process for N seconds/things in your hook_cron() implementation, and in both ...
Berdir's user avatar
  • 83.5k
12 votes

Cron drupal 8 for my module?

A modified example from cron_example module. This doesn't concern the interval the cron tasks are set in cron. This is important, as you will probably set another cron tasks sooner or latter with ...
Anish Sheela's user avatar
9 votes
Accepted

How can execute batch api over cron jobs

Instead of using Cron API you could provide your own custom Drush command and implement Batch API there. And then execute this Drush command using your server's crontab. Following comes a sample ...
Ashish Deynap's user avatar
9 votes
Accepted

How to implement a cron job for every minute and every 5 minutes?

hook_cron() The engine will then call the hook whenever a cron run happens, as defined by the administrator. In other words, hook_cron gets executed after a cron run happens. So if you have ...
No Sssweat's user avatar
  • 31.6k
7 votes

Programmatically get the results of a view

You can not get the value of field directly from row result. You can get it by accessing to the entity like the following: Option1 foreach ($view->result as $id => $result) { $node = $...
berramou's user avatar
  • 7,288
6 votes

How to check if an item exists in a Queue?

Add this function: /** * Adding item to queue. * * @param string $queue_id * The name of the queue to work with. * @param array $item_data * Arbitrary data to be associated with the new task ...
qzmenko's user avatar
  • 180
6 votes

How can I automate the "Clear Cache" everyday?

Despite you saying it didn't work with cron, I would suggest using cron in some way. :) The CacheFlush module claims to allow configuration of this via its UI (although I haven't used it so cannot ...
rooby's user avatar
  • 14.7k
6 votes

What is the mechanism behind class comments?

The class comments are Annotations : What is Annotation mean ? In general according to techopedia.com Annotation is a term used in computer programming to refer to documentation and comments that ...
berramou's user avatar
  • 7,288
5 votes

Use hook_cron to send daily mail but I get 4~5 the same mail every day?

D7, I struggled a lot, this is what i did, works perfect, following modules are required: Job shcheduler, Rules, and optionally Rules switch user, i use core cron; make a custom module 'MYMODULE' and ...
pinueve's user avatar
  • 1,578
5 votes

How to get list of cron tasks?

For Drupal 8/9, you can simply use the following command: drush php-eval 'var_dump(\Drupal::moduleHandler()->getImplementations("cron"))'
kmakaveev's user avatar
5 votes
Accepted

Cron tasks don't work: Could the Domain Access module be the cause?

The error is coming obviously from these lines of code in the cron settings form, when it tries to build the cron link: $cron_url = $this->url('system.cron', ['key' => $this->state->get('...
4uk4's user avatar
  • 102k
5 votes
Accepted

What is the relationship between hook_cron() and hook_cron_queue_info()?

The relationship is they are 2 independent hooks that can be used in conjunction with one another depending on what the task is. hook_cron(): Provides a means to supply a custom function to respond ...
Shawn Conn's user avatar
  • 26.9k
4 votes
Accepted

How to clear form cache automatically?

There are several method to clear the cache_form automatically. Use optimizedb module There is well-known issue with fast-growing table cache_form. This table stores Drupal form cache and it ...
Yuseferi's user avatar
  • 22.2k
4 votes

Drush command to run cron won't work in Crontab

I ran into a similar issue multiple times. I think in all cases cron was running a different version of php. To fix I ended up having to define my php path in my drush call: */5 * * * * /usr/local/...
albertski's user avatar
  • 3,497
4 votes

Programmatically get the results of a view

In my case, the '$result->_entity' was empty, so I had to get the value from the '$result->_object' : function YOUR_THEME_preprocess_views_view__YOUR_VIEW_ID(array &$variables): void { foreach (...
Ahmad Miri's user avatar
4 votes

What is the mechanism behind class comments?

Those are called annotations, and in this context, they are used for plugin discovery. This: cron = {"time" = 60} Signifies a property of the QueueWorker annotation; specifically QueueWorker::$cron,...
Clive's user avatar
  • 168k
4 votes
Accepted

How many temporary files will be deleted on every cron run?

Yes, the query is set to 100 items per cron run. You can see the associated code for it in file_cron(). $fids = Drupal::entityQuery('file') ->accessCheck(FALSE) ->condition('status', ...
Ryan Hartman's user avatar
3 votes

Delete directory from private folder programatically?

Interesting. Did you try using the following functions? I think one of them should work: file_unmanaged_delete_recursive drupal_rmdir Make sure that PHP has permission to delete the directories. To ...
Jigarius's user avatar
  • 3,127
3 votes
Accepted

Delete directory from private folder programatically?

Note that glob('*') ignores all hidden files by default. This means it does not return files that start with a dot (e.g. .file). If you want to match those files too, you can use {,.}* as the ...
Wim Mostrey's user avatar
  • 2,847
3 votes
Accepted

Execute system cron manually

To execute just the system_cron() hook, the easiest way is with drush $ drush php-eval 'system_cron();' This will start a PHP process, boostrap Drupal, and run the input. Note that this will run ...
mpdonadio's user avatar
  • 38.1k
3 votes

How to run a cron queue programmatically?

For one of my project, this worked for me :- $queue_machine_name = 'sync_product_list'; $queue = \Drupal::queue($queue_machine_name); $queue_worker = \Drupal::service('plugin.manager.queue_worker')-&...
sanket jain's user avatar
3 votes

EntityFieldQuery doesn't work correctly in hook_cron

Another workaround is running the query as user 1: $query->entityCondition('entity_type', 'node') ->propertyCondition('type', array('order_status')) ->propertyCondition('status', 1) ...
lmeurs's user avatar
  • 410
3 votes

how to make cron run once at specific time per day?

This is an old question, but I recently had to implement a similar feature in Drupal 8, so this might be helpful to others. Guarantee that a cron task runs exactly once per day, as close to a ...
Christoph Burschka's user avatar
3 votes
Accepted

How to force cron to use config saved during a SimpleTest?

As commented, you were missing the save call in the test. That means that the change is only in the runtime object returned by getEditable() and since get() and getEditable() do not share the static ...
Berdir's user avatar
  • 83.5k
3 votes
Accepted

sql-dump failing when run as cron

After much frustration I have resolved the issue and will post the answer in case it is of use. Cron seems to not always have access to the same PATH information as when a normal user - or even root -...
tanbog's user avatar
  • 1,293
3 votes

How to use cron to delete nodes of a content type that does not allow deletion by anonymous users

Not sure if you want to consider using it, but the Rules switch user module might be an acceptable compromise. Some details about it (from its project page): This module adds two new Rules actions: ...
Pierre.Vriens's user avatar
3 votes
Accepted

How do I set up Search API index as cron task?

You are right insofar as a node will only get reindexed when it is updated. Someone viewing the node isn't seen as an update, so incrementing the number of views won't cause the node to be reindexed. ...
Alfred Armstrong's user avatar
3 votes
Accepted

Why is this property of the Cron service initialized in this manner?

It's backward compatibility. Strictly speaking, constructors are excluded from BC, but the reality is that it is fairly common that one has to override them to inject additional dependencies. The ...
Berdir's user avatar
  • 83.5k
3 votes

Ensure that all Cron jobs work correctly

Maybe. Considering there are 20 cron jobs and they all run 15 times a day and you’re using advanced queue, I would make sure to test in your production environment timeouts and memory issues. ...
rovr138's user avatar
  • 1,018
3 votes
Accepted

Finding nodes that have not been indexed

The status of node indexing is based on the search_dataset. This table stores content keyword blobs and their associated sid, the primary key for the content's keyword (i.e. the nid). When compared/...
Shawn Conn's user avatar
  • 26.9k

Only top scored, non community-wiki answers of a minimum length are eligible