How to mock a constructor - Junit test case development issues
While writing JUnit test cases, we encounter cases like we want to initialize a…
March 18, 2018
hook_cron() suggests to put tasks that executes in shorter time or non-resource intensive tasks.
Mine was neither executing in shorter time nor non-resource intensive!
Drupal provides two hooks:
Create a file: mytestmodule.module
function mytestmodule_cron() {
$queue = DrupalQueue::get('name-of-my-queue'); //queue name can be any string you want
$test = array('29102', '1322', '2322'); //some random numbers
foreach ($test as $t) {
$queue->createItem($t);
}
}
function mytestmodule_cron_queue_info() {
$info['name-of-my-queue'] = array(
'worker callback' => 'mytestmodule_do_tasks',
'time' => 60,
);
return $info;
}
function mytestmodule_do_tasks($data) {
//do something with data
//For each cron run, this function will get called number of times I have created tasks
}
In hook_cron function, I have defined a queue, and put 3 tasks to it. Note: a single task can be to save a node. Here, you should have all the data you require to initiate a task.
In hook_cron_queue_info function, I have defined a callback function which will receive each task separately. And, specified a timeout value in seconds.
My callback function will be called as many number of times, as the number of tasks.
So, in this example, mytestmodule_do_tasks will receive values: 29012, 1322, 2322 independently.
Hope it helps.
While writing JUnit test cases, we encounter cases like we want to initialize a…
You have drupal 7 image from docker hub, and want to connect tomongo db via php…
The problem comes while using FTPS. When developer uses login method of this…
Introduction Javascript is not a strict type language. We can use a variable to…
Listing down the commonly used Elastic Search queries. You can get search…
Introduction Assume you have a drupal website and using cloudflare. You are…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…