Method: Grubby#fulfill
- Defined in:
- lib/grubby.rb
#fulfill(uri, purpose = "") {|resource| ... } ⇒ Object?
Ensures only-once processing of the resource indicated by uri for
the specified purpose. The given block is executed and the result
is returned if and only if the Grubby instance has not recorded a
previous call to fulfill for the same resource and purpose.
Note that the resource is identified by both its URI and its content hash. The latter prevents superfluous and rearranged URI query string parameters from interfering with only-once processing.
If #journal is set, and if the block does not raise an exception, the resource and purpose are logged to the journal file. This enables only-once processing across multiple program runs. It also provides a means to resume batch processing after an unexpected termination.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/grubby.rb', line 210 def fulfill(uri, purpose = "") series = [] uri = uri.to_absolute_uri return unless add_fulfilled(uri, purpose, series) normalized_uri = normalize_uri(uri) return unless add_fulfilled(normalized_uri, purpose, series) Grubby.logger.info("Fetch #{normalized_uri}") resource = get(normalized_uri) unprocessed = add_fulfilled(resource.uri, purpose, series) & add_fulfilled("content hash: #{resource.content_hash}", purpose, series) result = yield resource if unprocessed CSV.open(journal, "a") do |csv| series.each{|entry| csv << entry } end if journal result end |