raes 0.1.3 → 0.2.4

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: f85a9824a67f03b829de900a8a6bbc81fb9acd1608fd70d5ee3cc1cbc1265662
4
- data.tar.gz: c1b09916edaca6db620931e5823cd0bbc2666b4287223150acafb50ff9002ef5
3
+ metadata.gz: b322c6dca84a77e0b17ac2fb9ce842635eb0c5d5f6405eb2bcdcec001708a633
4
+ data.tar.gz: aa5d3c7441e74634b1b856feb37f507716c448caed16aca3604ab4c11e2c0309
5
5
  SHA512:
6
- metadata.gz: 28af8898db1f4a68d174eba88a2f78ac7309247892b4765ae908fc56def1c294d99fbc87f2847e557ef94885160769f5414964ab97d4efae51affe736355e933
7
- data.tar.gz: a9ed484de220441b3b322468dbed119f55263baca3e38cc40cc5ecbf52676d6fe38b376aec2db994cfe1a5d0b2e14da56ec002e6f24091dbac7f661f3112d92f
6
+ metadata.gz: 46a505cb7bef7f48f3e38e37834a94fe17e1aa1bc3186393ad9d3fbcc74914be675441561452ffe212155e4d4733b42cf2628e3c9656bfa9bf5742af94082f63
7
+ data.tar.gz: 137c325f5e506548dacdf8845eb93de58c51e51e4edd5430090763d1b86fc0e922150a28bf28a0543b7220b432191ea71f87745489f8d55618d082c2312ecffc
@@ -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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Raes::Engine.routes.draw do
4
+ # engine routes
4
5
  end
@@ -3,6 +3,7 @@
3
3
  require 'raes/engine'
4
4
  require 'raes/use_caller'
5
5
  require 'raes/use_context_logger'
6
+ require 'raes/use_memory_limit'
6
7
  require 'raes/use_storage'
7
8
  require 'raes/dispatch'
8
9
  require 'raes/reducer'
@@ -10,7 +11,7 @@ require 'raes/reducer'
10
11
  module Raes
11
12
  def self.config
12
13
  @config ||= Rails.application.config_for(:raes)
13
- rescue StandardError => e
14
+ rescue StandardError
14
15
  @config = {}
15
16
  end
16
17
 
@@ -21,4 +22,8 @@ module Raes
21
22
  def self.search(name)
22
23
  Action.search(name)
23
24
  end
25
+
26
+ def self.stateless(name, payload = {})
27
+ StatelessJob.perform_later(name.to_s, payload)
28
+ end
24
29
  end
@@ -23,10 +23,11 @@ module Raes
23
23
  end
24
24
 
25
25
  def create_state
26
- if @action.name.constantize.instance_method(:initialize).arity.zero?
27
- @action.name.constantize.call
26
+ klass = @action.name.constantize
27
+ if klass.instance_method(:initialize).arity.zero?
28
+ klass.call
28
29
  else
29
- @action.name.constantize.call(JSON.parse(@action.payload).symbolize_keys)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raes
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.4'
5
5
  end
metadata CHANGED
@@ -1,35 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - ogom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: get_process_mem
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 6.0.3
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 6.0.3.2
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 6.0.3
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
30
38
  - - ">="
31
39
  - !ruby/object:Gem::Version
32
- version: 6.0.3.2
40
+ version: '6.0'
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: factory_bot_rails
35
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +95,7 @@ files:
87
95
  - app/controllers/raes/application_controller.rb
88
96
  - app/helpers/raes/application_helper.rb
89
97
  - app/jobs/raes/application_job.rb
98
+ - app/jobs/raes/stateless_job.rb
90
99
  - app/jobs/raes/subscribe_job.rb
91
100
  - app/mailers/raes/application_mailer.rb
92
101
  - app/models/raes/action.rb
@@ -103,6 +112,7 @@ files:
103
112
  - lib/raes/reducer.rb
104
113
  - lib/raes/use_caller.rb
105
114
  - lib/raes/use_context_logger.rb
115
+ - lib/raes/use_memory_limit.rb
106
116
  - lib/raes/use_storage.rb
107
117
  - lib/raes/version.rb
108
118
  - lib/tasks/raes_tasks.rake