Class: Ungulate::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/ungulate/job.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Job

Returns a new instance of Job.



5
6
7
8
9
10
# File 'lib/ungulate/job.rb', line 5

def initialize(options = {})
  @logger = options[:logger] || ::Logger.new($stdout)
  @blob_processor = options[:blob_processor]
  @storage = options[:storage]
  @http = options[:http]
end

Instance Method Details

#process(encoded_job) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ungulate/job.rb', line 12

def process(encoded_job)
  @attributes = YAML.load(encoded_job)
  bucket = @storage.bucket(@attributes[:bucket], :listener => self)
  versions = @attributes[:versions]
  blob = bucket.retrieve(@attributes[:key])

  @blob_processor.process(
    :blob => blob, :versions => versions,
    :bucket => bucket, :original_key => @attributes[:key]
  )
end

#storage_complete(version) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ungulate/job.rb', line 24

def storage_complete(version)
  stored_versions << version

  if @attributes[:notification_url] && stored_versions == versions_to_process
    @http.put @attributes[:notification_url]
  end
end