Module: ActiveStorage::AsyncVariants::VariantWithRecordExtension
- Defined in:
- lib/active_storage/async_variants/variant_with_record_extension.rb
Instance Method Summary collapse
- #async_state ⇒ Object
- #enqueue! ⇒ Object
- #error ⇒ Object
- #failed? ⇒ Boolean
- #last_heartbeat_at ⇒ Object
- #pending? ⇒ Boolean
-
#processed ⇒ Object
Block vanilla ActiveStorage’s synchronous transform on bucket-backed services; rely on the auto-enqueue (AttachmentExtension) path – and the public #enqueue! – to dispatch ProcessJob.
- #processed? ⇒ Boolean
- #processing? ⇒ Boolean
- #progress ⇒ Object
- #progress_known? ⇒ Boolean
- #url ⇒ Object
Instance Method Details
#async_state ⇒ Object
61 62 63 64 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 61 def async_state return nil unless blob.bucket_backed? async_record&.state || "pending" end |
#enqueue! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 13 def enqueue! if result = find_named_async_variant , variant_name, _ = result blob.variant_records.create!( variation_digest: variation.digest, state: "pending", ) ActiveStorage::AsyncVariants::ProcessJob.perform_later( .record, .name, variant_name.to_s, ) end rescue ActiveRecord::RecordNotUnique # another caller (or a leftover record) wins; their job handles it end |
#error ⇒ Object
57 58 59 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 57 def error async_record&.error end |
#failed? ⇒ Boolean
53 54 55 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 53 def failed? async_record&.state == "failed" end |
#last_heartbeat_at ⇒ Object
74 75 76 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 74 def last_heartbeat_at async_record&.last_heartbeat_at end |
#pending? ⇒ Boolean
49 50 51 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 49 def pending? async_record.nil? || async_record.state == "pending" end |
#processed ⇒ Object
Block vanilla ActiveStorage’s synchronous transform on bucket-backed services; rely on the auto-enqueue (AttachmentExtension) path – and the public #enqueue! – to dispatch ProcessJob.
9 10 11 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 9 def processed blob.bucket_backed? ? self : super end |
#processed? ⇒ Boolean
37 38 39 40 41 42 43 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 37 def processed? if blob.bucket_backed? async_record&.state == "processed" else super end end |
#processing? ⇒ Boolean
45 46 47 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 45 def processing? async_record&.state == "processing" end |
#progress ⇒ Object
66 67 68 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 66 def progress async_record&.progress end |
#progress_known? ⇒ Boolean
70 71 72 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 70 def progress_known? !async_record&.progress.nil? end |
#url ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/active_storage/async_variants/variant_with_record_extension.rb', line 29 def url(...) if blob.bucket_backed? && async_variant? && !processed? blob.url(...) else super end end |