bricolage-streamingload 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1aacc6209260b4c74e823fc9ea903bdd811c4d2b
4
- data.tar.gz: c0b869e51e67a22708dd36b22afefb275e9a3169
3
+ metadata.gz: 523da5342b4a48ba2c46e2a2565bf1561570e7a7
4
+ data.tar.gz: '02229582ac7ee8ca27a86eaef69a4c4824735e8e'
5
5
  SHA512:
6
- metadata.gz: b6721bcb5c9dd506c801e71970e450e6a9318eac5171df099906ef91236e516a14f155cdd952240a534b80ab82771a88e22db49b309c8ab9cb210e1ae0747f1a
7
- data.tar.gz: 95469bdc023a41ab08f4b0d6df776b95ef733949a87fb5e053f9bf0b1d74c75f35cde9b89335fe12ea486a214364cddcb9c263c7340bbdbdbd5f16f541f66653
6
+ metadata.gz: 17e440e8400bf237cc4d19bd01c6f16641e6e49a595a757e2e2925de9ae5645796f29acda03904230e0bf591311b44267f2cd77ecec03245c8a553bba94e4b93
7
+ data.tar.gz: 0ffbc7699e531268e471d769024b64281111fa44c5fb4d3e94245202e0ee6504996db814a29eb497d339f2c20f38af63ec37de5731bc23e272191d04dc296a4c
@@ -7,6 +7,7 @@ require 'bricolage/streamingload/dispatchermessage'
7
7
  require 'bricolage/streamingload/loadermessage'
8
8
  require 'bricolage/streamingload/chunkrouter'
9
9
  require 'bricolage/streamingload/chunkbuffer'
10
+ require 'bricolage/streamingload/loadtasklogger'
10
11
  require 'bricolage/streamingload/alertinglogger'
11
12
  require 'aws-sdk'
12
13
  require 'yaml'
@@ -48,11 +49,16 @@ module Bricolage
48
49
 
49
50
  chunk_router = ChunkRouter.for_config(config.fetch('url_patterns'))
50
51
 
52
+ task_logger = LoadTaskLogger.new(
53
+ ctx.get_data_source('s3', config.fetch('ctl-s3-ds', 's3_ctl'))
54
+ )
55
+
51
56
  dispatcher = Dispatcher.new(
52
57
  event_queue: event_queue,
53
58
  task_queue: task_queue,
54
59
  chunk_router: chunk_router,
55
60
  chunk_buffer: chunk_buffer,
61
+ task_logger: task_logger,
56
62
  dispatch_interval: config.fetch('dispatch-interval', 60),
57
63
  logger: logger
58
64
  )
@@ -60,13 +66,13 @@ module Bricolage
60
66
  Process.daemon(true) if opts.daemon?
61
67
  create_pid_file opts.pid_file_path if opts.pid_file_path
62
68
  Dir.chdir '/'
63
- dispatcher.event_loop
64
- rescue SystemExit
65
- ;
66
- rescue Exception => e
67
- logger.exception e
68
- logger.error "dispatcher abort: pid=#{$$}"
69
- raise
69
+ begin
70
+ dispatcher.event_loop
71
+ rescue Exception => e
72
+ logger.exception e
73
+ logger.error "dispatcher abort: pid=#{$$}"
74
+ raise
75
+ end
70
76
  end
71
77
 
72
78
  def Dispatcher.new_logger(path, config)
@@ -85,11 +91,12 @@ module Bricolage
85
91
  # ignore
86
92
  end
87
93
 
88
- def initialize(event_queue:, task_queue:, chunk_router:, chunk_buffer:, dispatch_interval:, logger:)
94
+ def initialize(event_queue:, task_queue:, chunk_router:, chunk_buffer:, task_logger:, dispatch_interval:, logger:)
89
95
  @event_queue = event_queue
90
96
  @task_queue = task_queue
91
97
  @chunk_router = chunk_router
92
98
  @chunk_buffer = chunk_buffer
99
+ @task_logger = task_logger
93
100
  @dispatch_interval = dispatch_interval
94
101
  @dispatch_message_id = nil
95
102
  @logger = logger
@@ -198,6 +205,7 @@ module Bricolage
198
205
  tasks.each do |task|
199
206
  msg = StreamingLoadV3LoaderMessage.for_load_task(task)
200
207
  @task_queue.put msg
208
+ @task_logger.log task
201
209
  end
202
210
  end
203
211
 
@@ -0,0 +1,37 @@
1
+ require 'stringio'
2
+
3
+ module Bricolage
4
+
5
+ module StreamingLoad
6
+
7
+ class LoadTaskLogger
8
+
9
+ def initialize(s3ds)
10
+ @s3ds = s3ds
11
+ end
12
+
13
+ def log(task)
14
+ csv = content(task)
15
+ key = key(task)
16
+ @logger.info "s3: put: #{@s3ds.url(key)}"
17
+ @s3ds.object(key).put(body: csv)
18
+ end
19
+
20
+ def key(task)
21
+ now = Time.now
22
+ "task/#{now.strftime('%Y/%m/%d')}/task-#{task.id}.csv"
23
+ end
24
+
25
+ def content(task)
26
+ buf = StringIO.new
27
+ tasks.chunks.each do |chunk|
28
+ buf.puts %Q("#{task.id}","#{chunk.id}","#{chunk.url}")
29
+ end
30
+ buf.string
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Bricolage
2
2
  module StreamingLoad
3
- VERSION = '0.13.0'
3
+ VERSION = '0.14.0'
4
4
  end
5
5
  end
@@ -50,11 +50,14 @@ module Bricolage
50
50
  }
51
51
  ])
52
52
 
53
+ task_logger = DummyLoadTaskLogger.new
54
+
53
55
  dispatcher = Dispatcher.new(
54
56
  event_queue: event_queue,
55
57
  task_queue: task_queue,
56
58
  chunk_buffer: chunk_buffer,
57
59
  chunk_router: chunk_router,
60
+ task_logger: task_logger,
58
61
  dispatch_interval: 600,
59
62
  logger: ctx.logger
60
63
  )
@@ -93,6 +96,10 @@ module Bricolage
93
96
  assert_equal 'testschema', task.schema_name
94
97
  assert_equal 'desttable', task.table_name
95
98
  assert_equal 10, task.object_urls.size
99
+
100
+ # Task Logger
101
+ assert_not_nil task_logger.last_task
102
+ assert_equal task_id, task_logger.last_task.id.to_i
96
103
  end
97
104
 
98
105
  def unassigned_objects(ctl_ds)
@@ -142,11 +149,14 @@ module Bricolage
142
149
  }
143
150
  ])
144
151
 
152
+ task_logger = DummyLoadTaskLogger.new
153
+
145
154
  dispatcher = Dispatcher.new(
146
155
  event_queue: event_queue,
147
156
  task_queue: task_queue,
148
157
  chunk_buffer: chunk_buffer,
149
158
  chunk_router: chunk_router,
159
+ task_logger: task_logger,
150
160
  dispatch_interval: 600,
151
161
  logger: ctx.logger
152
162
  )
@@ -186,6 +196,10 @@ module Bricolage
186
196
  assert_equal 'testschema', task.schema_name
187
197
  assert_equal 'bbb', task.table_name
188
198
  assert_equal 2, task.object_urls.size
199
+
200
+ # Task Logger
201
+ assert_not_nil task_logger.last_task
202
+ assert_equal task_id, task_logger.last_task.id.to_i
189
203
  end
190
204
 
191
205
  def unassigned_table_objects(ctl_ds, table_name)
@@ -205,5 +219,23 @@ module Bricolage
205
219
 
206
220
  end
207
221
 
222
+
223
+ class DummyLoadTaskLogger
224
+
225
+ def initialize
226
+ @task = nil
227
+ end
228
+
229
+ def log(task)
230
+ @task = task
231
+ nil
232
+ end
233
+
234
+ def last_task
235
+ @task
236
+ end
237
+
238
+ end
239
+
208
240
  end
209
241
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bricolage-streamingload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-01-05 00:00:00.000000000 Z
12
+ date: 2018-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bricolage
@@ -130,6 +130,7 @@ files:
130
130
  - lib/bricolage/streamingload/jobparams.rb
131
131
  - lib/bricolage/streamingload/loadermessage.rb
132
132
  - lib/bricolage/streamingload/loadtask.rb
133
+ - lib/bricolage/streamingload/loadtasklogger.rb
133
134
  - lib/bricolage/streamingload/manifest.rb
134
135
  - lib/bricolage/streamingload/taskhandler.rb
135
136
  - lib/bricolage/streamingload/version.rb