embulk-plugin-input-sfdc-event-log-files 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/embulk/input_sfdc_event_log_files.rb +42 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26d4a69db8632348b043774556a10b3c7bbff8e3
|
4
|
+
data.tar.gz: a2a7cfd359eb9a89625a4cc0f1bdd0229f236fc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d54660a917a3d419f3adef4a7f3cd9e3f7cd155323a04c3b26a6e3cdd0746c518793c1cca543a48caf9f0e5901cfa7b451a8eaefd84bd416a563aefdae5a8273
|
7
|
+
data.tar.gz: 51b9b0c0724aa171876c611af1df816535a4a267dfb8286484413b97f05238693899bc11d277c8242ae5e956aceed1bc6087ecf4d049622b09e3860a69dd394d
|
data/README.md
CHANGED
@@ -3,4 +3,6 @@ embulk-plugin-input-sfdc-event-log-files
|
|
3
3
|
|
4
4
|
Embulk plugin for Salesforce.com Event Log Files input
|
5
5
|
|
6
|
-
|
6
|
+
At this moment this plugin is a sample implementation of InputPlugin.
|
7
|
+
Without GuessPlugin implementation you cannot create proper schema configuration.
|
8
|
+
Stay tuned.
|
@@ -20,17 +20,23 @@ module Embulk
|
|
20
20
|
'last_log_date' => config.param('last_log_date', :string, default: '0001-01-01T00:00:00Z'),
|
21
21
|
'max_retry_times' => config.param('max_retry_times', :integer, default: 2),
|
22
22
|
}
|
23
|
-
idx = -1
|
24
|
-
schema = config.param('schema', :array).map { |c| idx += 1; Column.new(idx, c['name'], c['type'].to_sym) }
|
25
23
|
threads = config.param('threads', :integer, default: 2)
|
26
|
-
|
24
|
+
idx = -1
|
25
|
+
schema = config.param('schema', :array, default: []).map { |c| idx += 1; Column.new(idx, c['name'], c['type'].to_sym) }
|
27
26
|
|
28
27
|
begin
|
29
|
-
|
30
|
-
|
28
|
+
client = HTTPClient.new
|
29
|
+
parsed = oauth(client, task)
|
30
|
+
task['instance_url'] = parsed['instance_url']
|
31
|
+
task['access_token'] = parsed['access_token']
|
32
|
+
init_client(client, task)
|
31
33
|
|
32
|
-
|
34
|
+
task['records'] = query(client, task)
|
33
35
|
|
36
|
+
if schema.empty?
|
37
|
+
raise 'empty schema given'
|
38
|
+
end
|
39
|
+
reports = yield(task, schema, threads)
|
34
40
|
last_log_date_report = reports.max_by { |report|
|
35
41
|
report['last_log_date']
|
36
42
|
}
|
@@ -41,10 +47,15 @@ module Embulk
|
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
50
|
+
def init_client(client, task)
|
51
|
+
client.base_url = task['instance_url']
|
52
|
+
client.default_header = { 'Authorization' => 'Bearer ' + task['access_token'] }
|
53
|
+
client
|
54
|
+
end
|
55
|
+
|
44
56
|
private
|
45
57
|
|
46
|
-
def oauth(task)
|
47
|
-
client = task['client']
|
58
|
+
def oauth(client, task)
|
48
59
|
params = {
|
49
60
|
:grant_type => 'password',
|
50
61
|
:client_id => task['oauth_client_id'],
|
@@ -54,15 +65,11 @@ module Embulk
|
|
54
65
|
}
|
55
66
|
with_retry(task) {
|
56
67
|
res = client.post(task['login_url'] + '/services/oauth2/token', params, :Accept => 'application/json; charset=UTF-8')
|
57
|
-
|
58
|
-
client.base_url = parsed['instance_url']
|
59
|
-
client.default_header = { 'Authorization' => 'Bearer ' + parsed['access_token'] }
|
60
|
-
nil
|
68
|
+
JSON.parse(res.body)
|
61
69
|
}
|
62
70
|
end
|
63
71
|
|
64
|
-
def query(task)
|
65
|
-
client = task['client']
|
72
|
+
def query(client, task)
|
66
73
|
query = "Select LogDate, EventType, LogFile from EventLogFile Where LogDate > #{task['last_log_date']}"
|
67
74
|
with_retry(task) {
|
68
75
|
res = client.get('/services/data/v32.0/query/', :q => query)
|
@@ -83,30 +90,34 @@ module Embulk
|
|
83
90
|
end
|
84
91
|
end
|
85
92
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@records = task['records']
|
90
|
-
@last_log_date = Time.parse(task['last_log_date'])
|
91
|
-
@client = task['client']
|
92
|
-
end
|
93
|
+
attr_reader :task
|
94
|
+
attr_reader :schema
|
95
|
+
attr_reader :page_builder
|
93
96
|
|
94
97
|
def run
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
+
client = self.class.init_client(HTTPClient.new, task)
|
99
|
+
records = task['records']
|
100
|
+
last_log_date = Time.parse(task['last_log_date'])
|
101
|
+
columns = schema.map { |c| c.name }
|
102
|
+
records.each do |record|
|
98
103
|
event_type = record['EventType']
|
99
|
-
|
104
|
+
last_log_date = [last_log_date, Time.parse(record['LogDate']).to_i].max
|
100
105
|
log_file = record['LogFile']
|
101
|
-
|
102
|
-
|
103
|
-
|
106
|
+
log_body = client.get_content(log_file)
|
107
|
+
CSV.parse(log_body, headers: true) do |row|
|
108
|
+
if row['TIMESTAMP']
|
109
|
+
begin
|
110
|
+
row['TIMESTAMP'] = Time.parse(row['TIMESTAMP']).to_i
|
111
|
+
rescue
|
112
|
+
# ignore
|
113
|
+
end
|
114
|
+
end
|
115
|
+
page_builder.add(row.to_hash.values_at(*columns).map(&:to_s))
|
104
116
|
end
|
105
117
|
end
|
106
|
-
|
107
|
-
|
118
|
+
page_builder.finish unless records.empty?
|
108
119
|
commit_report = {
|
109
|
-
'last_log_date' =>
|
120
|
+
'last_log_date' => last_log_date.xmlschema
|
110
121
|
}
|
111
122
|
commit_report
|
112
123
|
end
|