CMTV
Well-known member
I am trying to send emails to all thread watchers. Many hosts have restrictions on amount of emails sent per minute/hour.
@Mike advised me to use jobs system to avoid timeouts.
I am absolutely new to jobs topic and have not found any tutorials but I did understand something.
As I understand,
How to set at least 1 minute delay before rerunning job?
@Mike advised me to use jobs system to avoid timeouts.
I am absolutely new to jobs topic and have not found any tutorials but I did understand something.
As I understand,
$this->resume();
immediately re-queues job and runs run(...)
method.How to set at least 1 minute delay before rerunning job?
PHP:
public function run($maxRunTime)
{
$start = microtime(true);
$db = $this->app->db();
$query = "SELECT user_id, email_subscribe FROM xf_thread_watch WHERE thread_id = ? ORDER BY user_id";
/* Getting watchers */
$watchers = $db->fetchAll(
$db->limit(
$query,
$this->data['amount_to_get'],
$this->data['limit']
),
$this->data['thread_id']
);
if(!$watchers) // All watchers are notified
{
return $this->complete();
}
/* Iterating through watchers */
foreach($watchers as $watcher)
{
if(microtime(true) - $start >= $maxRunTime)
{
break;
}
$this->data['limit'] = $watcher['user_id'];
/* Notifying watcher (sending alert and email) ... */
}
/* ============================== */
/* ? 1 minute delay ? */
/* ============================== */
return $this->resume();
}