Crawler統合概要

説明

Crawler統合コンポーネントは、gb_consoleデータベースとPLG API(Crawlerシステム)間の通信を管理します。Crawlerにサマリーデータ設定を送信してクロールジョブの作成・更新を行い、失敗したクロール操作に関する情報を受信します。このコンポーネントはSendToCrawlerコマンドを使用してサマリーデータを処理し、作成または更新操作を通じてCrawlerで利用できるよう準備します。

システム概要図

---
config:
  theme: base
  layout: dagre
  flowchart:
    curve: linear
    htmlLabels: true
  themeVariables:
    edgeLabelBackground: "transparent"
---
flowchart TD
    %% Step 1: Database Tables at the top
    subgraph DatabaseTables["<div style='width:300px'>データベーステーブル (gb_console)</div>"]
        direction LR
        WishlistProducts[(summary_wishlist_products)]
        WishlistProductReviews[(summary_wishlist_product_reviews)]
        WishlistCategories[(summary_wishlist_categories)]
        WishlistSearchQueries[(summary_wishlist_search_queries)]
    end
    
    %% Step 2: Identify records with NotSent status for creation
    DatabaseTables --> CreateConfigsStep1[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>1</span>
            <p style='margin-top: 8px'>未送信レコード特定</p>
        </div>
    ]
    
    %% Step 3: Identify records needing updates (parallel to step 2)
    DatabaseTables --> UpdateConfigsStep2[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>2</span>
            <p style='margin-top: 8px'>更新必要レコード特定</p>
        </div>
    ]
    
    %% Step 4: Create and Update Configurations
    CreateConfigsStep1 --> CreateConfigs[設定作成]
    UpdateConfigsStep2 --> UpdateConfigs[設定更新]
    
    %% Step 5: Process data for Crawler
    CreateConfigs --> SummaryServiceStep3[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>3</span>
            <p style='margin-top: 8px'>API用データフォーマット</p>
        </div>
    ]
    UpdateConfigs --> SummaryServiceStep3
    
    %% Step 6: Summary Service Processing
    SummaryServiceStep3 --> SummaryService[サマリー処理]
    
    %% Step 7: Send to Crawler API
    SummaryService --> CrawlerStep4[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>4</span>
            <p style='margin-top: 8px'>Crawlerに送信</p>
        </div>
    ]
    
    %% Step 8: Crawler API
    CrawlerStep4 --> Crawler((PLG API))
    
    %% Step 9: Fetch failed jobs (separate flow)
    Crawler --> SyncFailedStep5[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #99cc66 !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>5</span>
            <p style='margin-top: 8px'>失敗ジョブ取得</p>
        </div>
    ]
    
    %% Step 10: Sync Failed Jobs
    SyncFailedStep5 --> SyncFailed[失敗ジョブ同期]
    
    %% Step 11: Update status in database
    SyncFailed --> TableUpdateStep6[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #99cc66 !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>6</span>
            <p style='margin-top: 8px'>エラーステータス更新</p>
        </div>
    ]
    
    %% Step 12: Back to Database Tables
    TableUpdateStep6 --> DatabaseTables
    
    style Crawler fill:#fcd9d9,stroke-width:2px
    style SummaryService fill:#fcf3d2
    style CreateConfigs fill:#d9f2d9
    style UpdateConfigs fill:#d9f2d9
    style SyncFailed fill:#d9f2d9
    style DatabaseTables fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
    style WishlistProducts fill:#d9f2d9,stroke:#339933,stroke-width:1px
    style WishlistProductReviews fill:#d9f2d9,stroke:#339933,stroke-width:1px
    style WishlistCategories fill:#d9f2d9,stroke:#339933,stroke-width:1px
    style WishlistSearchQueries fill:#d9f2d9,stroke:#339933,stroke-width:1px
    style CreateConfigsStep1 fill:transparent,stroke:transparent,stroke-width:1px
    style UpdateConfigsStep2 fill:transparent,stroke:transparent,stroke-width:1px
    style SummaryServiceStep3 fill:transparent,stroke:transparent,stroke-width:1px
    style CrawlerStep4 fill:transparent,stroke:transparent,stroke-width:1px
    style SyncFailedStep5 fill:transparent,stroke:transparent,stroke-width:1px
    style TableUpdateStep6 fill:transparent,stroke:transparent,stroke-width:1px

    %% Style for arrows
    linkStyle default stroke-width:2px,stroke:#333
    
    %% Subgraph classes
    classDef databaseClass fill:#fff9db
    class DatabaseTables databaseClass

詳細データフロー依存関係

Crawler統合コンポーネントは以下のデータフローに従います:

  1. gb_consoleデータベースのサマリーウィッシュリストテーブル(summary_wishlist_productssummary_wishlist_product_reviewssummary_wishlist_categoriessummary_wishlist_search_queries)にクロールが必要なデータを格納
  2. plg-api:sending-configs-to-crawlerコマンド(mode=create)がSendingStatus=NotSentのレコードを特定し、新しいクローラー設定が必要なものを識別
  3. サマリー処理サービスがデータタイプに応じてデータをフォーマットし、PLG API(Crawlerシステム)に送信
  4. 同じコマンド(mode=update)でクローラー設定の更新が必要なレコードを特定
  5. plg-api:sync-crawl-failed-from-crawlerコマンドが定期的にPLG APIから失敗したクロール操作の情報を取得
  6. 影響を受けたレコードのcrawl_statusを更新して失敗を反映(CrawlStatus=Error)

データタイプ

システムはクローラー統合のために4つの異なるデータタイプを処理します:

  • SummaryProduct ('product'):製品ID、モールID、入力タイプなどのプロパティを持つ製品データ
  • SummaryProductReview ('reviews'):サマリー製品との関係を持つ製品レビューデータ
  • SummaryCategory ('category_ranking_group'):カテゴリIDとモールIDを持つカテゴリデータ
  • SummarySearchQuery ('sq_ranking_group'):キーワードとモールIDを持つ検索クエリデータ

頻度概要

タイムライン

timeline
    title Crawler統合スケジュール
    section 設定作成/更新
        5分毎<br>(例: 08.00) : plg-api sending configs to crawler --mode=create
                              : plg-api sending configs to crawler --mode=update
    section 失敗クロール同期
        30分毎<br>(例: 08.30) : plg-api sync crawl failed from crawler

注意: すべてのコマンドは各データタイプ(SummaryProduct、SummaryProductReview、SummaryCategory、SummarySearchQuery)に対して実行されます

期待される結果

これらのコマンドが正常に実行されると、システムは以下を提供します:

  • 自動クローラー設定管理:新しいサマリーデータレコードが自動的に特定され、クローラー設定作成のためにPLG APIに送信
  • リアルタイム設定更新:サマリーデータが変更された際に既存のクローラー設定が更新され、クローラーが最新のパラメータで動作することを保証
  • 失敗クロール検出と復旧:失敗したクロール操作が自動的に検出され、そのステータスがデータベースに同期されて監視と再試行メカニズムに利用
  • マルチデータタイプ処理:4つの異なるデータタイプ(製品、レビュー、カテゴリ、検索クエリ)の同時処理とタイプ固有のフォーマット・API統合
  • ステータス追跡と監視:運用可視性のためのすべてのサマリーデータタイプにわたる送信ステータスとクロールステータスの包括的な追跡
  • データ整合性維持:適切な外部キー関係とステータス更新により、コンソールデータベースとクローラーシステム間のデータ一貫性を保証

データベーススキーマ

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 "クローラーへの送信ステータス"
        integer crawl_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への外部キー"
        integer schedule_id "スケジュールのID"
        integer schedule_priority "スケジュールの優先度"
        integer sending_status "クローラーへの送信ステータス"
        integer crawl_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 "クローラーへの送信ステータス"
        integer crawl_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 "クローラーへの送信ステータス"
        integer crawl_status "クロールのステータス"
        bigint crawl_config_id "CrawlerのconfigsテーブルのID(nullable)"
        integer status "製品のステータス"
    }
    
    summary_wishlist_products ||--o| summary_wishlist_product_reviews : "has one"

バッチリスト

名前 説明
設定作成 Crawlerの新しい設定を作成するために5分毎に実行されるコマンド
設定更新 Crawlerの既存設定を更新するために5分毎に実行されるコマンド
失敗クロール同期 失敗したクロール操作の情報を同期するために30分毎に実行されるコマンド