diff --git a/submodules/letsencrypt/hosting_letsencrypt.module b/submodules/letsencrypt/hosting_letsencrypt.module index 23199a8..c3be627 100644 --- a/submodules/letsencrypt/hosting_letsencrypt.module +++ b/submodules/letsencrypt/hosting_letsencrypt.module @@ -23,12 +23,13 @@ function hosting_letsencrypt_hosting_queues() { $queues['lets_encrypt'] = array( 'name' => t("Let's Encrypt"), 'description' => t("Refresh expiring Let's Encrypt certificates for HTTPS-enabled sites."), - 'type' => 'batch', + 'type' => HOSTING_QUEUE_TYPE_SPREAD, 'frequency' => strtotime("7 days", 0), 'min_threads' => 1, - 'max_threads' => 12, + 'max_threads' => 5, + 'count' => 5, 'threshold' => 100, - 'total_items' => count(hosting_letsencrypt_get_sites()), + 'total_items' => count(hosting_letsencrypt_get_sites(TRUE)), 'singular' => t('certificate renewal'), 'plural' => t('certificate renewals'), ); @@ -44,7 +45,8 @@ function hosting_letsencrypt_hosting_queues() { * renewed there if they're close to their expiry dates. */ function hosting_lets_encrypt_queue($count) { - foreach (hosting_letsencrypt_get_sites() as $site_id) { + foreach (hosting_letsencrypt_get_sites(TRUE, $count) as $site_id) { + /* @todo Ideally we'd be running this in the backend directly. */ if ($task = hosting_add_task($site_id, 'verify')) { watchdog('hosting_letsencrypt', t('Certificate renewal: Queuing Verify task ID %task for site %site with ID %id', array( '%task' => $task->nid, @@ -66,16 +68,29 @@ function hosting_lets_encrypt_queue($count) { * * @todo Ensure sites are using the Let's Encrypt service. */ -function hosting_letsencrypt_get_sites() { +function hosting_letsencrypt_get_sites($queue_only = FALSE, $limit = 0) { $sites = array(); + $where_extra = ''; + if ($queue_only) { + // Only sites not verified in the last month should be checked. + $where_extra .= ' AND s.verified <= :time '; + } + $limit_extra = ''; + if ($limit) { + $limit_extra .= ' LIMIT :count '; + } + if ($result = db_query('SELECT s.nid ' . 'FROM {hosting_site} s, {hosting_https_site} h ' . 'WHERE s.nid = h.nid ' . 'AND h.https_enabled IN(:https) ' - . 'AND s.status = :enabled', array( + . 'AND s.status = :enabled' . $where_extra + . 'ORDER BY s.verified ASC' . $limit_extra, array( ':https' => array(HOSTING_HTTPS_ENABLED, HOSTING_HTTPS_REQUIRED), ':enabled' => HOSTING_SITE_ENABLED, + ':time' => time() - (86400 * 7 * 4), + ':count' => $limit, ))) { while ($row = $result->fetch()) { $sites[] = $row->nid;