Crawler統合 - 設定更新
コマンドシグネチャ
php artisan plg-api:sending-configs-to-crawler --mode=update --data-type=SummaryProduct [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=update --data-type=SummaryProductReview [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=update --data-type=SummaryCategory [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=update --data-type=SummarySearchQuery [--limit=100]
目的
これらのコマンドは、異なるデータタイプのCrawlerシステム内の既存のクロール設定を更新します。サマリーウィッシュリストテーブル内で変更され、更新されたクローラー設定が必要なレコードを特定し、Playground APIを通じて変更された設定データをCrawlerシステムに送信します。
シーケンス図
sequenceDiagram
participant System
participant Command as plg-api:sending-configs-to-crawler (update)
participant Repository as SummaryWishlist*Repository
participant Job as Summary*Job
participant APIService as PlaygroundApiService
participant Crawler as Crawler System
participant Logger
participant Slack
Note over System,Slack: Crawler設定更新フロー(5分毎)
rect rgb(200, 255, 200)
Note right of System: 正常ケース - 通常処理
System->>Command: 特定のデータタイプで実行
Command->>Logger: コマンド開始をログ
Command->>Command: modeとdata-typeパラメータを検証
Command->>Repository: chunkDataSendToUpdate()
Repository->>Repository: WHERE sending_status = Sent AND needs update でレコードをクエリ
Repository-->>Command: レコードのチャンクを返す(最大:limitオプション)
rect rgb(200, 230, 255)
alt レコードが見つかった場合
Note right of Command: ジョブ処理
Command->>Job: dispatch(records)
Job->>Job: mapRecordsToData()
Job->>APIService: bulkUpdate(マップされたデータ)
APIService->>Crawler: HTTP PUT /bulk-update
Crawler-->>APIService: 更新された設定のレスポンス
APIService-->>Job: APIレスポンスを返す
rect rgb(230, 200, 255)
alt 成功レスポンス(200 OK)
Note right of Job: 成功処理
Job->>Repository: sending_statusをSentに更新
Job->>Repository: 変更された場合crawl_config_idを更新
Job->>Repository: 必要に応じてcrawl_statusを更新
Job->>Logger: 統計情報と共に成功をログ
Job->>Slack: 成功通知を送信
else Bad Request(400)
Note right of Job: エラー処理
Job->>Repository: sending_statusをErrorに更新
Job->>Logger: エラー詳細をログ
Job->>Slack: エラー通知を送信
end
end
else レコードなし
Note right of Command: データなしシナリオ
Command->>Logger: 処理するレコードがないことをログ
end
end
end
rect rgb(255, 200, 200)
Note right of System: エラーハンドリング
rect rgb(255, 230, 230)
alt 予期しないエラーが発生
Command->>Logger: エラー詳細をログ
Command->>Slack: コンテキスト付きエラー通知を送信
end
end
end
詳細
パラメータ
--mode=update:既存の設定を更新することを指定する必須パラメータ--data-type:設定を更新するデータのタイプを指定する必須パラメータSummaryProduct:製品サマリーデータSummaryProductReview:製品レビューデータSummaryCategory:カテゴリサマリーデータSummarySearchQuery:検索クエリサマリーデータ
--limit=N:チャンクサイズを制御するオプションパラメータ(デフォルト:100)
頻度
各データタイプに対して5分毎
依存関係
- サマリーウィッシュリストテーブルに変更されたsending_status = Sentのレコードが含まれている必要がある
- Playground APIサービスにアクセス可能である必要がある
- 有効なAPI認証トークン
- データベース内の既存のcrawl_config_id値
出力
テーブル
summary_wishlist_products:sending_status、crawl_config_id、crawl_statusを更新- sending_status:成功した更新ではSentのまま、失敗時はErrorに変更
- crawl_config_id:Crawlerが新しいIDを返した場合に更新される可能性
- crawl_status:Crawlerレスポンスに基づいて更新
summary_wishlist_product_reviews:製品と同じフィールド更新summary_wishlist_categories:製品と同じフィールド更新summary_wishlist_search_queries:製品と同じフィールド更新
サービス
- Playground API:変更されたクローラー設定でバルク更新リクエストを受信
- Crawlerシステム:サマリーデータの変更に基づいて既存のクロール設定を更新
データベーススキーマ
erDiagram
summary_wishlist_products {
bigint id PK
string input "製品の入力"
string input_type "入力のタイプ: jan, asin, rakuten_id"
bigint mall_id FK "mallsテーブルへの外部キー"
integer schedule_id "スケジュールのID"
integer schedule_priority "スケジュールの優先度"
integer sending_status "クローラーへの送信ステータス"
bigint crawl_config_id "CrawlerのconfigsテーブルのID(nullable)"
integer status "製品のステータス"
}
summary_wishlist_product_reviews {
bigint id PK
bigint summary_wishlist_product_id FK "summary_wishlist_productsへの外部キー(unique)"
integer schedule_id "スケジュールのID"
integer schedule_priority "スケジュールの優先度"
integer sending_status "クローラーへの送信ステータス"
bigint crawl_config_id "CrawlerのconfigsテーブルのID(nullable)"
integer status "製品のステータス"
}
summary_wishlist_categories {
bigint id PK
string category_id "モール内のカテゴリID"
bigint mall_id FK "mallsテーブルへの外部キー"
integer schedule_id "スケジュールのID"
integer schedule_priority "スケジュールの優先度"
integer sending_status "クローラーへの送信ステータス"
bigint crawl_config_id "CrawlerのconfigsテーブルのID(nullable)"
integer status "製品のステータス"
}
summary_wishlist_search_queries {
bigint id PK
bigint mall_id FK "モールのID"
string keyword "検索キーワード"
integer schedule_id "スケジュールのID"
integer schedule_priority "スケジュールの優先度"
integer sending_status "クローラーへの送信ステータス"
bigint crawl_config_id "CrawlerのconfigsテーブルのID(nullable)"
integer status "製品のステータス"
}
%% Relationships
summary_wishlist_products ||--o{ summary_wishlist_product_reviews : "has reviews"
エラーハンドリング
ログ
- データタイプとパラメータを含むコマンド実行の開始/終了
- レスポンスコードを含むAPI呼び出しの成功/失敗
- レコード数とバッチ処理情報
- デバッグ用のファイルと行情報を含む詳細なエラーメッセージ
Slack
- データタイプと処理統計(処理されたレコード数、更新された設定数)を含む成功通知
- 詳細なメッセージとソース情報を含むエラー通知
- APIレスポンス詳細と影響を受けたレコード数を含む完全なエラーコンテキスト
トラブルシューティング
データ確認
- summary_wishlist_*テーブルに変更されたsending_status = Sentのレコードが含まれていることを確認
- レコードに以前の作成操作からの有効なcrawl_config_id値があることを確認
- schedule_idとschedule_priority値が有効であることを確認
- updated_atタイムスタンプが最近の変更を示していることを検証
ログ確認
- 成功した開始と完了のコマンド実行ログを監視
- HTTPステータスコードとエラーメッセージのAPIレスポンスログを確認
- 成功/失敗パターンのSlack通知を確認
- 処理遅延や失敗のジョブキューログを調査
- 適切なステータス遷移を示すデータベース更新ログを確認
- 更新が適用されたことを確認するために設定データの前後を比較