raes 0.1.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/app/jobs/raes/stateless_job.rb +14 -0
- data/config/routes.rb +1 -0
- data/lib/raes.rb +12 -0
- data/lib/raes/context_logger.rb +40 -0
- data/lib/raes/reducer.rb +4 -3
- data/lib/raes/use_context_logger.rb +15 -0
- data/lib/raes/use_memory_limit.rb +28 -0
- data/lib/raes/version.rb +1 -1
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9392ed6cf1189aadf25bf2a88a7eae729622dd19a71b33a64d41783e1062fe00
|
4
|
+
data.tar.gz: 327a5cb0c338e933d91e41b0a34b01b5abd975e3d4448a5fa39da9bf5a332398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e167c1ff7f4b8a6685643f44ef4592165e1d73332785532866a2b371c9f22ed80cab3c77f101ca8f689626cdbaf28c851a68bc1e408de04a7e285a56fe98c6
|
7
|
+
data.tar.gz: ce567beb27fbcdba14a53450b6e3af91af5f5c344d4581602ed1f9aaf8f0d7860423a85e827cd9c5cbc16051e3a7c19856c8ef7ac0e9e317de6dfbd2285b9b4b
|
data/README.md
CHANGED
@@ -86,6 +86,25 @@ If use storage, then execute:
|
|
86
86
|
$ rails active_storage:install
|
87
87
|
```
|
88
88
|
|
89
|
+
## Configuration
|
90
|
+
|
91
|
+
Add the following to your config/raes.yml:
|
92
|
+
|
93
|
+
```yaml
|
94
|
+
default: &default
|
95
|
+
concern:
|
96
|
+
context_logger: Rails
|
97
|
+
|
98
|
+
development:
|
99
|
+
<<: *default
|
100
|
+
|
101
|
+
test:
|
102
|
+
<<: *default
|
103
|
+
|
104
|
+
production:
|
105
|
+
<<: *default
|
106
|
+
```
|
107
|
+
|
89
108
|
## Test
|
90
109
|
|
91
110
|
```bash
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raes
|
4
|
+
class StatelessJob < ApplicationJob
|
5
|
+
def perform(name, payload)
|
6
|
+
klass = name.constantize
|
7
|
+
if klass.instance_method(:initialize).arity.zero?
|
8
|
+
klass.call
|
9
|
+
else
|
10
|
+
klass.call(payload.symbolize_keys)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/raes.rb
CHANGED
@@ -2,11 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'raes/engine'
|
4
4
|
require 'raes/use_caller'
|
5
|
+
require 'raes/use_context_logger'
|
6
|
+
require 'raes/use_memory_limit'
|
5
7
|
require 'raes/use_storage'
|
6
8
|
require 'raes/dispatch'
|
7
9
|
require 'raes/reducer'
|
8
10
|
|
9
11
|
module Raes
|
12
|
+
def self.config
|
13
|
+
@config ||= Rails.application.config_for(:raes)
|
14
|
+
rescue StandardError
|
15
|
+
@config = {}
|
16
|
+
end
|
17
|
+
|
10
18
|
def self.dispatch(name, payload = {})
|
11
19
|
Dispatch.call(name, payload)
|
12
20
|
end
|
@@ -14,4 +22,8 @@ module Raes
|
|
14
22
|
def self.search(name)
|
15
23
|
Action.search(name)
|
16
24
|
end
|
25
|
+
|
26
|
+
def self.stateless(name, payload = {})
|
27
|
+
StatelessJob.perform_later(name.to_s, payload)
|
28
|
+
end
|
17
29
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raes
|
4
|
+
class ContextLogger
|
5
|
+
def initialize(class_name)
|
6
|
+
@class_name = class_name
|
7
|
+
@logger_class = logger_class
|
8
|
+
end
|
9
|
+
|
10
|
+
def debug(message)
|
11
|
+
@logger_class.logger.debug context(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def info(message)
|
15
|
+
@logger_class.logger.info context(message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def warn(message)
|
19
|
+
@logger_class.logger.warn context(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def error(message)
|
23
|
+
@logger_class.logger.error context(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fatal(message)
|
27
|
+
@logger_class.logger.fatal context(message)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def context(message)
|
33
|
+
{ class: @class_name, message: message }
|
34
|
+
end
|
35
|
+
|
36
|
+
def logger_class
|
37
|
+
(Raes.config.dig(:concern, :context_logger) || 'Rails').constantize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/raes/reducer.rb
CHANGED
@@ -23,10 +23,11 @@ module Raes
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_state
|
26
|
-
|
27
|
-
|
26
|
+
klass = @action.name.constantize
|
27
|
+
if klass.instance_method(:initialize).arity.zero?
|
28
|
+
klass.call
|
28
29
|
else
|
29
|
-
|
30
|
+
klass.call(JSON.parse(@action.payload).symbolize_keys)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raes
|
4
|
+
module UseMemoryLimit
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def memsize
|
9
|
+
GetProcessMem.new(Process.pid).mb.ceil
|
10
|
+
end
|
11
|
+
|
12
|
+
def memsize_with_gc
|
13
|
+
size = memsize
|
14
|
+
if !memory_limit.zero? && size > memory_limit
|
15
|
+
GC.start
|
16
|
+
size = memsize
|
17
|
+
end
|
18
|
+
size
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def memory_limit
|
25
|
+
@memory_limit ||= Raes.config.dig(:concern, :memory_limit).to_i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/raes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ogom
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 6.0.3.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: get_process_mem
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: factory_bot_rails
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +101,7 @@ files:
|
|
87
101
|
- app/controllers/raes/application_controller.rb
|
88
102
|
- app/helpers/raes/application_helper.rb
|
89
103
|
- app/jobs/raes/application_job.rb
|
104
|
+
- app/jobs/raes/stateless_job.rb
|
90
105
|
- app/jobs/raes/subscribe_job.rb
|
91
106
|
- app/mailers/raes/application_mailer.rb
|
92
107
|
- app/models/raes/action.rb
|
@@ -97,10 +112,13 @@ files:
|
|
97
112
|
- db/migrate/20200628202001_create_raes_actions.rb
|
98
113
|
- db/migrate/20200628202002_create_raes_storages.rb
|
99
114
|
- lib/raes.rb
|
115
|
+
- lib/raes/context_logger.rb
|
100
116
|
- lib/raes/dispatch.rb
|
101
117
|
- lib/raes/engine.rb
|
102
118
|
- lib/raes/reducer.rb
|
103
119
|
- lib/raes/use_caller.rb
|
120
|
+
- lib/raes/use_context_logger.rb
|
121
|
+
- lib/raes/use_memory_limit.rb
|
104
122
|
- lib/raes/use_storage.rb
|
105
123
|
- lib/raes/version.rb
|
106
124
|
- lib/tasks/raes_tasks.rake
|
@@ -109,7 +127,7 @@ licenses:
|
|
109
127
|
- MIT
|
110
128
|
metadata:
|
111
129
|
allowed_push_host: https://rubygems.org/
|
112
|
-
post_install_message:
|
130
|
+
post_install_message:
|
113
131
|
rdoc_options: []
|
114
132
|
require_paths:
|
115
133
|
- lib
|
@@ -125,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
143
|
version: '0'
|
126
144
|
requirements: []
|
127
145
|
rubygems_version: 3.0.3
|
128
|
-
signing_key:
|
146
|
+
signing_key:
|
129
147
|
specification_version: 4
|
130
148
|
summary: Summary of Rails Async Event Store.
|
131
149
|
test_files: []
|