feat: add scheduled task for IndexNow submissions

- Make the `perform` method accept an optional parameter for recent updates
- Log the number of URLs submitted to IndexNow
- Introduce a new scheduled job for submitting URLs to IndexNow daily

This commit enhances the functionality of the `SubmitToIndexnowWorker` by allowing
it to be triggered via a scheduled job. It also adds logging for better monitoring
of submissions, improving traceability and performance in sitemap management.
This commit is contained in:
songtianlun 2025-04-08 14:21:54 +08:00
parent e8aa6fc388
commit f6cf64e5b8
2 changed files with 9 additions and 1 deletions

View File

@ -14,7 +14,7 @@ class SubmitToIndexnowWorker
"https://www.bing.com/indexnow"
]
def perform(recent)
def perform(recent = true)
lock_key = "submit_to_indexnow_lock"
lock_ttl = 300 # 锁的生存时间,单位为秒
@ -29,6 +29,7 @@ class SubmitToIndexnowWorker
# 收集所有需要提交的 URLs
urls = collect_urls(recently_updated)
Rails.logger.info "Ready to submit #{urls.size} URLs to IndexNow"
# 分批提交 URLs (每批最多 10000 个 URLs符合 IndexNow 限制)
urls.each_slice(100) do |url_batch|

View File

@ -11,6 +11,13 @@ refresh_sitemap:
description: "Refresh sitemap daily"
enabled: true
submit_indexnow:
cron: '0 5 * * *'
class: SubmitToIndexnowWorker
queue: default
description: "Refresh sitemap daily"
enabled: true
clean_ahoy_data:
cron: '0 0 * * 0'
class: CleanAhoyDataWorker