TopicFile Sync with ActiveStorage

オープン
#26 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rails, ruby
領域
backend, database

調査の方向性

まず TopicFileSync と TopicFile モデルの場所を特定し、次に ActiveStorage の設定と既存のデータベースマイグレーションを調査します。issue のフィールドから SyncProgress モデルとマイグレーションを定義し、各ファイルのダウンロードに進捗更新を関連付け、中断された同期を再開でき、完了したファイルと失敗したファイルが記録されることを検証します。

索引モデルが issue の本文から書いたものです。

説明

cross-app sync

Sync files and attach using ActiveStorage

  class TopicFileSync
    def sync(file_data, topic)
      topic_file = TopicFile.find_or_initialize_by(external_id: file_data["id"])

      # Skip if checksum unchanged (file hasn't changed on server)
      return topic_file if topic_file.external_checksum == file_data["checksum"]

      # Download and verify
      downloaded_path = downloader.download(file_data["id"], expected_checksum: file_data["checksum"])
      verifier.verify!(downloaded_path, file_data["checksum"])

      # Attach via ActiveStorage
      File.open(downloaded_path, "rb") do |io|
        topic_file.file.attach(
          io: io,
          filename: file_data["filename"],
          content_type: file_data["content_type"]
        )
      end

      topic_file.update!(
        topic: topic,
        filename: file_data["filename"],
        file_type: extract_file_type(file_data["content_type"]),
        file_size: file_data["size_bytes"],
        external_checksum: file_data["checksum"]
      )

      topic_file
    ensure
      FileUtils.rm_f(downloaded_path) if downloaded_path
    end
  end

Track and persist download progress for resume

  • Create SyncProgress model:
create_table :sync_progress do |t|
  t.string :manifest_version
  t.string :status  # pending, downloading, completed, failed
  t.integer :total_files
  t.integer :completed_files
  t.integer :total_bytes
  t.integer :downloaded_bytes
  t.json :pending_file_ids  # files remaining to download
  t.json :failed_file_ids   # files that failed
  t.timestamps
end
  • Update progress after each file download
  • Use for resume after interruption/restart
主要言語
HTML
スター
4
フォーク
0
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rubyforgood/skillrx-beacon のほかの issue

rubyforgood/skillrx-beacon の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。