Skip to content

保守クリーンアップバッチ

目的

WordPress の運用中に増え続ける一時データやログを、WP-Cron で定期的に掃除する。対象は期限切れ transient と debug.log

対象バッチ

バッチCron hook実行頻度schedule sync主な処理
期限切れ transient クリーンアップslot_kouryaku_daily_transient_cleanupdailyadmin_initdelete_expired_transients(true) を実行する
debug.log ローテーションslot_kouryaku_daily_debug_log_rotationdailyinit priority 20期限切れローテーション済みログを削除し、肥大化した debug.log をローテーションする

どちらも schedule sync を transient で 1 日 1 回までに間引く。

期限切れ transient クリーンアップ

TransientCleanupScheduler が daily cron を登録し、実行時に delete_expired_transients(true) を呼び出す。外部オブジェクトキャッシュが有効な場合でも、options テーブル側に残った期限切れ transient を掃除対象にするため、強制フラグ true を渡す。

多重実行対策

項目内容
ロックslot_kouryaku_transient_cleanup_lock option
取得方法add_option() の UNIQUE 制約を使って原子的に取得する
TTL1時間
stale 対応不正値または TTL 超過のロックは削除して再取得を試す

debug.log ローテーション

DebugLogRotationScheduler が daily cron を登録し、DebugLogServiceInterface::resolve_log_path() で対象ログを解決してから処理する。

項目内容
ローテーション閾値100MB 超過(DebugLogMaintenanceConstants::MAX_LOG_BYTES
保持期間ローテーション済み debug.log.N を 14 日保持(mtime 基準)
ロックDebugLogRotationLock
  1. DebugLogRotator::purge_expired_rotated_files() で期限切れのローテーション済みログを削除する。
  2. DebugLogRotationLock::try_acquire() でロックを取る。
  3. DebugLogRotator::rotate_if_oversized() で閾値超過時のみ debug.log をローテーションする。
  4. ローテーションが発生した場合は error_log に結果を記録する。

障害再発防止の運用背景は サイト障害再発防止 を参照する。

参照ファイル

  • core_src/Admin/transient_cleanup/TransientCleanupScheduler.php
  • core_src/Admin/debug_log/DebugLogRotationScheduler.php
  • core_src/Util/debug_log_rotator/DebugLogRotator.php
  • core_src/Util/debug_log_rotator/DebugLogRotationLock.php
  • core_src/Bootstrap/service_provider/AdminServiceProvider.php