Class: GoodDataMarketo::ETL

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata_marketo/models/etl.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ ETL

Returns a new instance of ETL.



4
5
6
7
# File 'lib/gooddata_marketo/models/etl.rb', line 4

def initialize config = {}
  @queue = config[:queue]
  @marketo = config[:marketo] || config[:client]
end

Instance Method Details

#determine_loads_state(config = {}) ⇒ Object



9
10
11
12
13
14
15
16
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gooddata_marketo/models/etl.rb', line 9

def determine_loads_state config = {}

  loads = @marketo.loads(:user => GOODDATA_USER,
                         :pass => GOODDATA_PASSWORD,
                         :project => GOODDATA_PROJECT,
                         :marketo_client => @marketo)

  if loads.available?

    file = loads.available.first
    load = loads.create :name => file

    load.execute

    # Data from the job can now be accessed ARRAY load.storage
    # load.storage

    # Increment the load by one day if it is time related.

    case load.json[:method]

      when 'get_changes'

        time_increment = config[:increment] || (12*60*60)
        oca = load.arguments[:oldest_created_at]
        lca = load.arguments[:latest_created_at]

        load.arguments[:oldest_created_at] = (Time.parse(oca) + time_increment).to_s
        load.arguments[:latest_created_at] = (Time.parse(lca) + time_increment).to_s

        # If the latest time is later then today kill the load.
        if Time.parse(lca) > Time.now

          load.terminate

          self.determine_loads_state

          # Otherwise save the load and resume additional loads.
        else

          load.save

          self.determine_loads_state

        end

      when 'get_multiple'

        self.determine_loads_state

      else
        raise 'Unable to determine lead type ("get_multiple"/"get_changes")!'

    end

  else

    load = @queue.pop
    loads.create load

    self.determine_loads_state

  end

end