Crawler統合 - 設定作成

コマンドシグネチャ

php artisan plg-api:sending-configs-to-crawler --mode=create --data-type=SummaryProduct [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=create --data-type=SummaryProductReview [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=create --data-type=SummaryCategory [--limit=100]
php artisan plg-api:sending-configs-to-crawler --mode=create --data-type=SummarySearchQuery [--limit=100]

目的

これらのコマンドは、新しいクローラー設定が必要なサマリーウィッシュリストテーブル内のレコードを特定し、Playground APIを通じてCrawlerシステムに必要な設定データを送信します。各データタイプには独自の設定フォーマットがあり、効率的なクロール操作を維持するために個別に処理されます。

シーケンス図

sequenceDiagram
    participant System
    participant Command as plg-api:sending-configs-to-crawler (create)
    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: chunkDataSendToCreate()
    Repository->>Repository: WHERE sending_status = NotSent OR Error でレコードをクエリ
    Repository-->>Command: レコードのチャンクを返す(最大:limitオプション)
    
    rect rgb(200, 230, 255)
    alt レコードが見つかった場合
        Note right of Command: ジョブ処理
        Command->>Job: dispatch(records)
        
        Job->>Job: mapRecordsToData()
        Job->>APIService: bulkCreate(マップされたデータ)
        APIService->>Crawler: HTTP POST /bulk-create
        Crawler-->>APIService: 作成された設定のレスポンス
        APIService-->>Job: APIレスポンスを返す
        
        rect rgb(230, 200, 255)
        alt 成功レスポンス(201 Created)
            Note right of Job: 成功処理
            Job->>Repository: sending_statusをSentに更新
            Job->>Repository: レスポンスからcrawl_config_idを更新
            Job->>Repository: crawl_statusをNotCrawledに更新
            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=create:新しい設定を作成することを指定する必須パラメータ
  • --data-type:設定を作成するデータのタイプを指定する必須パラメータ
    • SummaryProduct:製品サマリーデータ
    • SummaryProductReview:製品レビューデータ
    • SummaryCategory:カテゴリサマリーデータ
    • SummarySearchQuery:検索クエリサマリーデータ
  • --limit=N:チャンクサイズを制御するオプションパラメータ(デフォルト:100)

頻度

各データタイプに対して5分毎

依存関係

  • サマリーウィッシュリストテーブルにsending_status = NotSentまたはErrorのレコードが含まれている必要がある
  • Playground APIサービスにアクセス可能である必要がある
  • 有効なAPI認証トークン

出力

テーブル

  • summary_wishlist_products:sending_status、crawl_config_id、crawl_statusを更新
    • sending_status:NotSent/ErrorからSentに変更
    • crawl_config_id:CrawlerレスポンスからのIDで設定
    • crawl_status:成功した作成に対してNotCrawledに設定
  • 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レスポンス詳細と影響を受けたレコード数を含む完全なエラーコンテキスト

トラブルシューティング

データ確認

  1. summary_wishlist_*テーブルにsending_status = NotSentまたはErrorのレコードが含まれていることを確認
  2. レコードに有効なschedule_idとschedule_priority値があることを確認
  3. mallsテーブルにmall_id参照が存在することを確認
  4. 製品のinput_type値(jan、asin、rakuten_id)を検証

ログ確認

  1. 成功した開始と完了のコマンド実行ログを監視
  2. HTTPステータスコードとエラーメッセージのAPIレスポンスログを確認
  3. 成功/失敗パターンのSlack通知を確認
  4. 処理遅延や失敗のジョブキューログを調査
  5. 適切なステータス遷移を示すデータベース更新ログを確認