worker_tools 1.2 → 1.3
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/.tool-versions +1 -0
- data/README.md +19 -0
- data/lib/worker_tools/memory_usage.rb +28 -0
- data/lib/worker_tools/version.rb +1 -1
- data/worker_tools.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a69e014d2d2959641972ad163b5567e957693c90b54ae9e7aec4a723f1f39c6
|
4
|
+
data.tar.gz: 3cc3536cf26ab79054761570671361d23bbcb2c708e4974ebfd07ea8671180f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d622417f3afd6057ae548f2b0e688ce1d8087d1e75a176ff4fe85caef5b1a1469e3ad07db2e21da2be6a365e97ba0bae18fbdd818f2eaea47bc7bb4e2fd0b7
|
7
|
+
data.tar.gz: e479438605973cf104b4c9d60cf3a7f821d09c053c7e569370afa7a1bbcc5e52006f65863a8a2085caa31f878df987c85d8daa7461c41f229aaa71094f9a6c2b
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.5
|
data/README.md
CHANGED
@@ -349,6 +349,25 @@ class MyImporter
|
|
349
349
|
end
|
350
350
|
```
|
351
351
|
|
352
|
+
## MemoryUsage
|
353
|
+
|
354
|
+
There is a memory usage wrapper that you can use to record the memory consumption of your worker tasks. The memory usage is recorded in megabytes and stored in `model.meta['memory_usage']`. The module uses the `get_process_mem` gem to measure memory usage before and after the task execution.
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
class MyImporter
|
358
|
+
include WorkerTools::MemoryUsage
|
359
|
+
wrappers :memory_usage
|
360
|
+
|
361
|
+
def run
|
362
|
+
# do stuff that consumes memory
|
363
|
+
end
|
364
|
+
|
365
|
+
# ..
|
366
|
+
end
|
367
|
+
```
|
368
|
+
|
369
|
+
The memory usage will be automatically recorded in the model's meta attribute as `memory_usage` with the value in megabytes (rounded to 2 decimal places). The measurement represents the difference in memory usage before and after the task execution.
|
370
|
+
|
352
371
|
## Module 'Notes'
|
353
372
|
|
354
373
|
If you use ActiveRecord you may need to modify the serializer as well as deserializer from the note attribute. After that you can easily serialize hashes and array of hashes with indifferent access. For that purpose the gem provides two utility methods. (HashWithIndifferentAccessType, SerializedArrayType). There is an example of how you can use it.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'get_process_mem'
|
2
|
+
|
3
|
+
module WorkerTools
|
4
|
+
module MemoryUsage
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
# rubocop:disable Metrics/MethodLength
|
9
|
+
def with_wrapper_memory_usage(&block)
|
10
|
+
memory_error = nil
|
11
|
+
start_memory = GetProcessMem.new.mb
|
12
|
+
|
13
|
+
begin
|
14
|
+
block.call
|
15
|
+
rescue StandardError => e
|
16
|
+
memory_error = e
|
17
|
+
ensure
|
18
|
+
end_memory = GetProcessMem.new.mb
|
19
|
+
memory_used = (end_memory - start_memory).round(2)
|
20
|
+
model.meta['memory_usage'] = memory_used if model.respond_to?(:meta)
|
21
|
+
end
|
22
|
+
|
23
|
+
raise memory_error if memory_error
|
24
|
+
end
|
25
|
+
# rubocop:enable Metrics/MethodLength
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/worker_tools/version.rb
CHANGED
data/worker_tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worker_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fsainz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: get_process_mem
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: roo
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,6 +243,7 @@ extra_rdoc_files: []
|
|
229
243
|
files:
|
230
244
|
- ".gitignore"
|
231
245
|
- ".rubocop.yml"
|
246
|
+
- ".tool-versions"
|
232
247
|
- ".travis.yml"
|
233
248
|
- CHANGELOG.md
|
234
249
|
- Gemfile
|
@@ -244,6 +259,7 @@ files:
|
|
244
259
|
- lib/worker_tools/csv_input.rb
|
245
260
|
- lib/worker_tools/csv_output.rb
|
246
261
|
- lib/worker_tools/errors.rb
|
262
|
+
- lib/worker_tools/memory_usage.rb
|
247
263
|
- lib/worker_tools/recorder.rb
|
248
264
|
- lib/worker_tools/slack_error_notifier.rb
|
249
265
|
- lib/worker_tools/utils/hash_with_indifferent_access_type.rb
|