Module: Rubino::API::Operations::Tasks::Serializer
- Defined in:
- lib/rubino/api/operations/tasks/serializer.rb
Overview
Wire shapes for background-subagent (‘task`) entries.
#summary powers the list endpoint — id/subagent/prompt/status/timing plus a short result preview, never the full body. #detail adds the complete result (success) or error (failure). The Entry struct carries Time objects and a live Thread/Runner; only the serializable fields are surfaced.
Constant Summary collapse
- RESULT_PREVIEW =
200
Class Method Summary collapse
- .detail(entry) ⇒ Object
-
.elapsed(entry) ⇒ Object
Wall-clock seconds: to finish if done, else to now for a live task.
- .iso(time) ⇒ Object
- .preview(result) ⇒ Object
- .summary(entry) ⇒ Object
Class Method Details
.detail(entry) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/rubino/api/operations/tasks/serializer.rb', line 31 def detail(entry) summary(entry).merge( finished_at: iso(entry.finished_at), result: entry.result, error: entry.error ) end |
.elapsed(entry) ⇒ Object
Wall-clock seconds: to finish if done, else to now for a live task.
44 45 46 47 48 |
# File 'lib/rubino/api/operations/tasks/serializer.rb', line 44 def elapsed(entry) return nil unless entry.started_at ((entry.finished_at || Time.now) - entry.started_at).round(3) end |
.iso(time) ⇒ Object
39 40 41 |
# File 'lib/rubino/api/operations/tasks/serializer.rb', line 39 def iso(time) time&.utc&.iso8601 end |
.preview(result) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/rubino/api/operations/tasks/serializer.rb', line 50 def preview(result) return nil if result.nil? str = result.to_s str.length > RESULT_PREVIEW ? "#{str[0, RESULT_PREVIEW]}…" : str end |
.summary(entry) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubino/api/operations/tasks/serializer.rb', line 19 def summary(entry) { id: entry.id, subagent: entry.subagent, prompt: entry.prompt, status: entry.status.to_s, started_at: iso(entry.started_at), elapsed_seconds: elapsed(entry), result_summary: preview(entry.result) } end |