Class: Embulk::InputSfdcEventLogFiles
- Inherits:
-
InputPlugin
- Object
- InputPlugin
- Embulk::InputSfdcEventLogFiles
- Defined in:
- lib/embulk/input_sfdc_event_log_files.rb
Instance Attribute Summary collapse
-
#page_builder ⇒ Object
readonly
Returns the value of attribute page_builder.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#page_builder ⇒ Object (readonly)
Returns the value of attribute page_builder.
92 93 94 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 92 def page_builder @page_builder end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
91 92 93 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 91 def schema @schema end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
90 91 92 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 90 def task @task end |
Class Method Details
.init_client(client, task) ⇒ Object
47 48 49 50 51 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 47 def init_client(client, task) client.base_url = task['instance_url'] client.default_header = { 'Authorization' => 'Bearer ' + task['access_token'] } client end |
.transaction(config, &control) ⇒ Object
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 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 12 def transaction(config, &control) oauth = config.param('oauth', :hash) task = { 'login_url' => config.param('login_url', :string, default: 'https://login.salesforce.com'), 'oauth_client_id' => oauth['id'], 'oauth_client_secret' => oauth['secret'], 'username' => config.param('username', :string), 'password' => config.param('password', :string), 'last_log_date' => config.param('last_log_date', :string, default: '0001-01-01T00:00:00Z'), 'max_retry_times' => config.param('max_retry_times', :integer, default: 2), } threads = config.param('threads', :integer, default: 2) idx = -1 schema = config.param('schema', :array, default: []).map { |c| idx += 1; Column.new(idx, c['name'], c['type'].to_sym) } begin client = HTTPClient.new parsed = oauth(client, task) task['instance_url'] = parsed['instance_url'] task['access_token'] = parsed['access_token'] init_client(client, task) task['records'] = query(client, task) reports = yield(task, schema, threads) last_log_date_report = reports.max_by { |report| report['last_log_date'] } config.merge(last_log_date_report) rescue # TODO: log raise end end |
Instance Method Details
#run ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/embulk/input_sfdc_event_log_files.rb', line 94 def run client = self.class.init_client(HTTPClient.new, task) records = task['records'] last_log_date = Time.parse(task['last_log_date']) records.each do |record| event_type = record['EventType'] last_log_date = [last_log_date, Time.parse(record['LogDate']).to_i].max log_file = record['LogFile'] log_body = client.get_content(log_file) CSV.parse(log_body, headers: true) do |row| if row['TIMESTAMP'] row['time'] = Time.parse(row['TIMESTAMP']).to_i rescue nil end page_builder.add(schema.map { |c| v = row[c.name] v = v.to_i if c.type == 'long' v }) end end page_builder.finish unless records.empty? commit_report = { 'last_log_date' => last_log_date.xmlschema } commit_report end |