work_shaper 0.1.0 → 0.1.2

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
  SHA256:
3
- metadata.gz: 5f008d410f5dc96fc854d8673b38873eacb66d176768d8c8ab8b78107a4b4837
4
- data.tar.gz: 621935ffcad5cd2db1b138a2fafeab86eeb5c86138437756a56768cae698a1ff
3
+ metadata.gz: 357d650ad73cfb685d1fd05a2ed98a0b4136358dc232febe04be921f8954855c
4
+ data.tar.gz: 77bceccf96220ec5ba98e438fde84761dd3494878fae05005cccdad0121cb833
5
5
  SHA512:
6
- metadata.gz: 2119feac5a3f1d5e56d69b572a8b764558625d68da7c63d7b7fa4e2747e92a204013fea4247cd5502317fed446ebb7f8826b130f9f15437895de2547a4c927d2
7
- data.tar.gz: 591f2a06d61f872e1d194b73dfac057f31b34f903512ba48b6864e9280d71b27ed83004e95274d4dd029ce978853f0dd81b126c5b5eb8e28014a3e9c169f89be
6
+ metadata.gz: 25c75b8e97b6e320e57164a2128ab320b23efe22c81d3e3f64857e70f92ee3dd881133060b702109ec1b172120a446ffb8d214a0423a039eb95ac4a6d06b3de3
7
+ data.tar.gz: 72babc90aaef951eb50dcc3edea4bc71903497bc79aaf3c7708fc143649407a88d4df6240d5f3b232a60fc37f11446f758109d833bc65d0822a23578b2da7ee6
data/README.md CHANGED
@@ -60,7 +60,13 @@ end
60
60
 
61
61
  max_in_queue = ENV.fetch('MAX_THREAD_QUEUE_SIZE', 25)
62
62
 
63
- work_shaper = WorkShaper::Manager.new(work, done, ack, error, max_in_queue)
63
+ work_shaper = WorkShaper::Manager.new(
64
+ work: work,
65
+ on_done: done,
66
+ ack: ack,
67
+ on_error: error,
68
+ max_in_queue: max_in_queue
69
+ )
64
70
 
65
71
  @value_to_subkey = {}
66
72
  max_sub_keys = ENV.fetch('MAX_SUB_KEYS', 100)
@@ -155,11 +155,11 @@ module WorkShaper
155
155
  received: @received_offsets[partition].to_a[0..10].join(',')
156
156
  })
157
157
  else
158
- @total_acked += 1
159
158
  @last_ack[partition] = offset
160
159
  end
161
160
  end
162
161
 
162
+ @total_acked += 1
163
163
  completed.delete(offset)
164
164
  received.delete(offset)
165
165
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WorkShaper
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/work_shaper.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "work_shaper/version"
4
4
  require_relative "work_shaper/manager"
5
5
  require_relative "work_shaper/worker"
6
+ require 'json'
6
7
 
7
8
  # WorkShaper is inspired by Kafka partitions and offsets, but could be used to organize and
8
9
  # parallelize other forms of work. The original goal was to parallelize processing offsets in
@@ -18,12 +19,25 @@ module WorkShaper
18
19
  def self.logger=(logger)
19
20
  @logger = logger
20
21
  end
22
+
21
23
  def self.logger
22
24
  @logger ||= Logger.new(
23
25
  $stdout,
24
26
  level: ENV['LOG_LEVEL'] || 'DEBUG',
25
- formatter: Ruby::JSONFormatter::Base.new
27
+ formatter: formatter
26
28
  )
27
29
  end
30
+
31
+ def self.formatter
32
+ proc do |severity, datetime, _progname, msg|
33
+ datefmt = datetime.strftime('%Y-%m-%dT%H:%M:%S.%6N')
34
+ {
35
+ timestamp: datefmt,
36
+ level: severity.ljust(5),
37
+ pid: Process.pid,
38
+ msg: msg
39
+ }.to_json + "\n"
40
+ end
41
+ end
28
42
  end
29
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_shaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Fernholz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorted_set