Class: AnimateIt::RenderStore
- Inherits:
-
Object
- Object
- AnimateIt::RenderStore
- Defined in:
- lib/animate_it/render_store.rb
Defined Under Namespace
Classes: Render
Constant Summary collapse
- CHANNEL =
"animate_it_renders".freeze
- TARGET =
"animate_it_renders".freeze
Class Method Summary collapse
- .all ⇒ Object
- .broadcast_append(render) ⇒ Object
- .broadcast_replace(render) ⇒ Object
- .cancel!(id) ⇒ Object
- .cancelled?(id) ⇒ Boolean
- .complete!(id) ⇒ Object
- .create!(id:, composition_id:, total_frames:, output_path:) ⇒ Object
- .fail!(id, error) ⇒ Object
- .fetch(id) ⇒ Object
-
.find(id) ⇒ Object
nil-tolerant lookup — returns nil when the render isn't registered (e.g. server restart cleared the in-memory store but a tab still holds the old render id).
- .html ⇒ Object
- .progress!(id, frame:, total_frames:) ⇒ Object
- .start!(id) ⇒ Object
Class Method Details
.all ⇒ Object
59 60 61 |
# File 'lib/animate_it/render_store.rb', line 59 def all synchronize { renders.values.reverse } end |
.broadcast_append(render) ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/animate_it/render_store.rb', line 84 def broadcast_append(render) return unless defined?(Turbo::StreamsChannel) Turbo::StreamsChannel.broadcast_append_to( CHANNEL, target: TARGET, html: render_row(render) ) end |
.broadcast_replace(render) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/animate_it/render_store.rb', line 74 def broadcast_replace(render) return unless defined?(Turbo::StreamsChannel) Turbo::StreamsChannel.broadcast_replace_to( CHANNEL, target: row_id(render.id), html: render_row(render) ) end |
.cancel!(id) ⇒ Object
49 50 51 |
# File 'lib/animate_it/render_store.rb', line 49 def cancel!(id) update!(id, status: :cancelled, error: "Cancelled by user") end |
.cancelled?(id) ⇒ Boolean
53 54 55 56 57 |
# File 'lib/animate_it/render_store.rb', line 53 def cancelled?(id) fetch(id).status == :cancelled rescue KeyError true end |
.complete!(id) ⇒ Object
40 41 42 43 |
# File 'lib/animate_it/render_store.rb', line 40 def complete!(id) render = fetch(id) update!(id, status: :complete, current_frame: render.total_frames) end |
.create!(id:, composition_id:, total_frames:, output_path:) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/animate_it/render_store.rb', line 23 def create!(id:, composition_id:, total_frames:, output_path:) render = nil synchronize do render = Render.new(id, composition_id, :queued, 0, total_frames, output_path.to_s, nil) renders[id] = render end broadcast_append(render) end |
.fail!(id, error) ⇒ Object
45 46 47 |
# File 'lib/animate_it/render_store.rb', line 45 def fail!(id, error) update!(id, status: :failed, error: error.) end |
.fetch(id) ⇒ Object
63 64 65 |
# File 'lib/animate_it/render_store.rb', line 63 def fetch(id) synchronize { renders.fetch(id) } end |
.find(id) ⇒ Object
nil-tolerant lookup — returns nil when the render isn't registered (e.g. server restart cleared the in-memory store but a tab still holds the old render id).
70 71 72 |
# File 'lib/animate_it/render_store.rb', line 70 def find(id) synchronize { renders[id] } end |
.html ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/animate_it/render_store.rb', line 94 def html <<~HTML <div id="#{TARGET}" class="animate-it-renders-list"> #{render_rows} </div> HTML end |
.progress!(id, frame:, total_frames:) ⇒ Object
36 37 38 |
# File 'lib/animate_it/render_store.rb', line 36 def progress!(id, frame:, total_frames:) update!(id, status: :rendering, current_frame: frame, total_frames:) end |
.start!(id) ⇒ Object
32 33 34 |
# File 'lib/animate_it/render_store.rb', line 32 def start!(id) update!(id, status: :rendering) end |