Skip to main content

Runbook

Các thao tác vận hành thường gặp cho builderx_api. Mỗi block dưới đây mặc định chạy trong IEx shell bên trong container (make bashiex -S mix), trừ khi có ghi chú khác.

Tài khoản

Tạo tài khoản mới:

BuilderxApi.Accounts.create_account(%{email: "example@gmail.com"})

Sinh link đăng nhập một lần (one-time login link):

BuilderxApi.Run.get_login_link("example@gmail.com")

Index sản phẩm vào Elasticsearch

  1. Bật các service hỗ trợ từ webcms:

    cd webcms && make beam
  2. Khởi động RabbitMQ consumer dùng cho indexer:

    BuilderxApi.DynamicApp.start_rabbit()
    Rabbit.IndexingConsumer.start_link()
    Rabbit.TaskPoolConsumer.start_link()
  3. Chạy hàm index:

    • Reindex toàn bộ sản phẩm:

      Elastic.re_setup_product_index()
    • Xóa index cũ sau khi reindex thành công:

      Elastic.confirm_re_setup_product_index()

Cache sản phẩm (ETS in-memory)

Warm cache sản phẩm cho một site:

# site_id là UUID, ví dụ "16952bde-3812-4373-8e9d-8c7c56857312"
BuilderxApi.Run.ets_cache_product_site(site_id)

Warm cache variation của site đó:

BuilderxApi.Run.ets_cache_agg_variations_by_site(site_id)

Cache danh mục

Warm cache danh mục cho một site:

BuilderxApi.Run.cache_category_has_many_products(site_id)

Xóa cache danh mục của một site:

BuilderxApi.Run.remove_cache_category_by_site(site_id)

Warm toàn bộ site:

BuilderxApi.Run.cache_category_all()

Xóa cache của toàn bộ site:

BuilderxApi.Run.remove_cache_category_all()

Import dữ liệu địa chỉ Việt Nam (mới)

BuilderxApi.Geo.ImportGeo.import_new_vietnam_addresses()

Import dữ liệu địa chỉ Việt Nam (cũ — 3 cấp)

Địa chỉ cũ gồm ba cấp hành chính: tỉnh → huyện → xã.

Import cả ba cấp cho Việt Nam (country code 84) trong một lệnh:

BuilderxApi.Geo.ImportGeo.import_country_addresses(84, [is_new: false, delete_old: true])

Hoặc chạy riêng từng cấp:

BuilderxApi.Geo.ImportGeo.import_vn_provinces()
BuilderxApi.Geo.ImportGeo.import_vn_districts()
BuilderxApi.Geo.ImportGeo.import_vn_commune()