Skip to content

Doc text from media async - #270

Merged
ledsun merged 8 commits into
pubannotation:masterfrom
Tamada-Arino:doc-text-from-media-async
Jul 23, 2026
Merged

Doc text from media async#270
ledsun merged 8 commits into
pubannotation:masterfrom
Tamada-Arino:doc-text-from-media-async

Conversation

@Tamada-Arino

@Tamada-Arino Tamada-Arino commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

概要

Ollama + moondreamを使用して画像からテキストを生成させ、Docのtextに加える一連の処理を非同期化しました。
他のJobと同じく10件以上Jobを登録できないようにしています。

動作確認

  • specが全件パスすることを確認しました。
  • ブラウザ上で動作確認を行いました。
    • doc新規画面で画像からテキストを生成させるチェックボックスにチェックを入れた状態で登録後、Jobが作成された旨のメッセージが表示されること
    • Job管理画面に画像からテキストを生成させるJobが追加されていること
    • エラーがあればMessageに追加されていること
    • Jobが10件ある状態で新しくJobを作れないこと

@github-actions github-actions Bot added the size/l label Jul 3, 2026
@Tamada-Arino
Tamada-Arino force-pushed the doc-text-from-media-async branch 2 times, most recently from 503a9e0 to 70a59d5 Compare July 23, 2026 00:17
Keep the async job's name consistent with DocGenerationsController and
the DocGenerationFromMedia service it delegates to.
…controller

The job already records raised errors as job messages via
UseJobRecordConcern, so the throwaway DocGenerationFromMedia instance
built only to call validate_medium! before enqueuing was redundant.
… finished yet

The message said "Doc created" before the job actually ran, which was
misleading since the doc doesn't exist until the async job completes.
Also drop the unused text_generation_pending key.
@Tamada-Arino
Tamada-Arino force-pushed the doc-text-from-media-async branch from 673e862 to 522a35c Compare July 23, 2026 00:56
@github-actions github-actions Bot added size/s and removed size/l labels Jul 23, 2026
Matches the existing per-project job cap used elsewhere (docs_controller,
projects_controller, annotations_controller, evaluations_controller) to
prevent unbounded job queueing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Asynchronously generates a Doc’s text from an attached image medium by enqueuing a background job (Ollama + moondream via ImageCaptionService), aligning this workflow with the app’s existing Job-record tracking and enforcing a 10-jobs-per-project cap.

Changes:

  • Switch DocGenerationsController#create from synchronous Doc creation to enqueuing DocGenerationFromMediaJob and returning a “started” notice.
  • Add DocGenerationFromMediaJob (tracked via UseJobRecordConcern) and a focused job spec.
  • Update request specs and i18n strings to reflect async behavior and job-limit enforcement.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/requests/doc_generations_spec.rb Updates request coverage for async enqueue/run behavior, error recording on jobs, and 10-job limit behavior.
spec/jobs/doc_generation_from_media_job_spec.rb Adds unit coverage ensuring the job delegates to DocGenerationFromMedia and exposes a human-readable job name.
config/locales/ja.yml Adds a localized “text generation started” notice for the async flow.
config/locales/en.yml Adds the English “text generation started” notice for the async flow.
app/jobs/doc_generation_from_media_job.rb Introduces the new background job wired into the Job-record tracking concern.
app/controllers/doc_generations_controller.rb Enqueues the job instead of creating the Doc synchronously; adjusts HTML/JSON responses accordingly and enforces the 10-job limit.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 19 to 22
respond_to do |format|
format.html { redirect_to show_project_sourcedb_sourceid_docs_path(@project.name, @doc.sourcedb, @doc.sourceid), notice: t('controllers.shared.successfully_created', model: t('activerecord.models.doc')) }
format.json { render json: @doc.to_hash, status: :created, location: @doc }
format.html { redirect_to project_docs_path(@project.name), notice: notice }
format.json { render json: { message: notice, job_name: active_job.job_name }, status: :accepted }
end

@Tamada-Arino Tamada-Arino Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 202 response previously gave clients no way to correlate the
request with the enqueued job. Follows the existing pattern in
DocsController#add_from_upload: look up the Job record by
active_job_id and expose its show URL for polling/log correlation.
@github-actions github-actions Bot added size/m and removed size/s labels Jul 23, 2026
@ledsun
ledsun merged commit 536d33d into pubannotation:master Jul 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants