WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Programmatically setup cron jobs in Drupal 8, 9

Submitted by barnettech on Mon, 06/08/2020 - 09:22

https://knackforge.com/blog/vamsi/how-create-queue-woker-drupal-8

in EmailQueue.php have the following file:

/**
* @file
* Contains \Drupal\mymodule\Plugin\QueueWorker\EmailQueue.
*/
namespace Drupal\Learning\Plugin\QueueWorker;
use Drupal\Core\Queue\QueueWorkerBase;
/**
* Processes Tasks for Learning.
*
* @QueueWorker(
* id = "email_queue",
* title = @Translation("Learning task worker: email queue"),
* cron = {"time" = 60}
* )
*/
class EmailQueue extends QueueWorkerBase {
/**
* {@inheritdoc}
*/
public function processItem($data) {
$mailManager = \Drupal::service('plugin.manager.mail');
$params = $data;
$mailManager->mail('learning', 'email_queue', $data['email'], 'en', $params , $send = TRUE);
}
}