Class: Mass::Job

Inherits:
BlackStack::Base
  • Object
show all
Defined in:
lib/base-line/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Job

Returns a new instance of Job.



9
10
11
12
13
# File 'lib/base-line/job.rb', line 9

def initialize(h)
    super(h)
    self.profile = Mass::Profile.new(h['profile']).child_class_instance if h['profile']
    self.source = Mass::Source.new(h['source_desc']).child_class_instance if h['source_desc']
end

Instance Attribute Details

#profileObject

Returns the value of attribute profile.



3
4
5
# File 'lib/base-line/job.rb', line 3

def profile
  @profile
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/base-line/job.rb', line 3

def source
  @source
end

Class Method Details

.object_nameObject



5
6
7
# File 'lib/base-line/job.rb', line 5

def self.object_name
    'job'
end

Instance Method Details

#can_download_images?Boolean

return true if the assigned profile can download multiple files (allow_browser_to_download_multiple_files) and the source can download pictures (download_pictures)

Returns:

  • (Boolean)


55
56
57
# File 'lib/base-line/job.rb', line 55

def can_download_images?
    self.profile.desc['allow_browser_to_download_multiple_files'] && self.source.desc['download_pictures']
end

#do(logger: nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/base-line/job.rb', line 46

def do(logger:nil)
    self.source.do(
        job: self,
        logger: logger,
    )
end

#upsertObject

Submit a hash descriptor to the server for an upsert. Optimizaton: remove the events from the job descriptor, and submit events one by one.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/base-line/job.rb', line 17

def upsert
    job = self
    events = job.desc['events'].dup
    job.desc['events'] = []
    
    # cap the number of events to job.desc['max_events']
    events = events[0..job.desc['max_events']-1] if job.desc['max_events'] && events.size > job.desc['max_events']

    # initialize the id_account and id_job for each event
    events.each { |e| 
        e['id_account'] = job.desc['id_account']
        e['id_job'] = job.desc['id'] 
    }

    # upsert the events
    events = events.map { |e| Mass::Event.new(e) }
    super()
    #k = 0
    #puts
    events.each { |e| 
        #k += 1
        #print "k: #{k}... "
        res = e.upsert 
        #puts res.nil? ? "nil" : res.desc['id']
    }

    job.desc['events'] = events.map { |e| e.desc } # setup the events array into the job again
end