1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rails7でherokuでrailsコマンドを動かす。(sitemapの自動更新)heroku scheduler

Last updated at Posted at 2023-03-07

やりたいこと

sitemap generatorのリフレッシュを、日本時間のAM4時に毎日自動で動かす。

設定

サイトマップの設定は下記。

gem wheneverのところで動かなかった

なるべく依存するgemを増やしたくない
ので、heroku schedulerを使って実行する方針へ変更。

heroku schedulerをインストールして下記のように設定。
登録したコマンド→ rails sitemap:refresh
image.png

時間は下記サイトを参考。(画像では日本時間の朝4時を狙っている。herokuで設定できるUTCと9時間の時差がある)

事前確認:ターミナルからheroku loginして手動実行できること

問題なく成功。

$ heroku run rails sitemap:refresh -a narou-susume2
Running rails sitemap:refresh on ⬢ narou-susume2... up, run.3661 (Basic)
In '/app/public/':
+ sitemap.xml.gz                                           3 links /  357 Bytes
Sitemap stats: 3 links / 1 sitemaps / 0m00s

Pinging with URL 'https://narou-osusume.com/sitemap.xml.gz':
  Successful ping of Google

明日追記

動くか確認し、結果を明日追記する。(現在3/7)
以下コマンドで実行ログを確認できるっぽい。

$ heroku logs --app アプリ名

3/8追記 問題なく動いていた。

サーチコンソールで最終読み込み日時が3/7→3/8に更新されていることを確認。

image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?