如何验证 ActiveStorage blob 是否实际存在?
How can I verify that an ActiveStorage blob is actually present?
我有一个应用程序已经 运行 生产了好几个月了,有数以万计的附件。今天早上,我尝试对其中一个附件进行操作,但出现以下错误:
Azure::Core::Http::HTTPError: BlobNotFound (404): The specified blob does not exist.
我可以轻松地重新创建此 blob,但这种情况让我想编写一个脚本来检查 所有 附件的完整性,并验证没有其他附件丢失. (我希望这是一个暂时性的网络错误,我希望找到的很少,但我需要安心。)
我可以看到有一个调用方法似乎完全符合我的需要:exist?(key)
,记录在此处:
https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/service/disk_service.rb
但是,我不知道应该怎么称呼它。根据 this,它是作为实例方法实现的。那么如何引用我的 Rails 应用程序的活动 ActiveStorage 实例 (取决于环境)来使用此方法?
我想知道是否有可能回溯获取 ActiveStorage::Service::AzureStorageService 的实例(在生产中),并在找到 class.[=17 的每个实例时发现 this answer =]
从那里,我发现我可以:
asass = ObjectSpace.each_object(ActiveStorage::Service::AzureStorageService).first
这让我可以:
2.5.5 :015 > asass.exist?(c.json.blob.key)
AzureStorage Storage (313.3ms) Checked if file exists at key: ....PTLWNbEFLgeB8Y5x.... (yes)
=> true
进一步深入研究 Rails' GitHub 问题使我发现可以通过存储对象的实例访问对 ActiveStorage 服务实例的引用,并且我总是可以使用 send()
方法来调用 它的 方法之一:
2.5.5 :045 > c.json.blob.service.send(:exist?, c.json.blob.key)
AzureStorage Storage (372.4ms) Checked if file exists at key: ....PTLWNbEFLgeB8Y5x.... (yes)
=> true
我确定这两种方法都点亮了相同的代码路径,但我不确定目前我更喜欢哪一种。我仍然认为必须存在某种方式来通过 app.
或 Rails.application.
遍历 Rails 实例以到达 ActiveStorage 实例,但我无法确定。
我有一个应用程序已经 运行 生产了好几个月了,有数以万计的附件。今天早上,我尝试对其中一个附件进行操作,但出现以下错误:
Azure::Core::Http::HTTPError: BlobNotFound (404): The specified blob does not exist.
我可以轻松地重新创建此 blob,但这种情况让我想编写一个脚本来检查 所有 附件的完整性,并验证没有其他附件丢失. (我希望这是一个暂时性的网络错误,我希望找到的很少,但我需要安心。)
我可以看到有一个调用方法似乎完全符合我的需要:exist?(key)
,记录在此处:
https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/service/disk_service.rb
但是,我不知道应该怎么称呼它。根据 this,它是作为实例方法实现的。那么如何引用我的 Rails 应用程序的活动 ActiveStorage 实例 (取决于环境)来使用此方法?
我想知道是否有可能回溯获取 ActiveStorage::Service::AzureStorageService 的实例(在生产中),并在找到 class.[=17 的每个实例时发现 this answer =]
从那里,我发现我可以:
asass = ObjectSpace.each_object(ActiveStorage::Service::AzureStorageService).first
这让我可以:
2.5.5 :015 > asass.exist?(c.json.blob.key)
AzureStorage Storage (313.3ms) Checked if file exists at key: ....PTLWNbEFLgeB8Y5x.... (yes)
=> true
进一步深入研究 Rails' GitHub 问题使我发现可以通过存储对象的实例访问对 ActiveStorage 服务实例的引用,并且我总是可以使用 send()
方法来调用 它的 方法之一:
2.5.5 :045 > c.json.blob.service.send(:exist?, c.json.blob.key)
AzureStorage Storage (372.4ms) Checked if file exists at key: ....PTLWNbEFLgeB8Y5x.... (yes)
=> true
我确定这两种方法都点亮了相同的代码路径,但我不确定目前我更喜欢哪一种。我仍然认为必须存在某种方式来通过 app.
或 Rails.application.
遍历 Rails 实例以到达 ActiveStorage 实例,但我无法确定。