nexaas-async-collector 3.2.0 → 3.3.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: a6f7dddb4c3f1de985620fc046e55ad5abe09d4d
4
- data.tar.gz: 4acb3b3d95a33a71139362f9b9b325e1c068e0be
3
+ metadata.gz: a17f015b0f574c0e61e461f95cbaac500bdd44a9
4
+ data.tar.gz: a8792061a11ac481b44b8ee714a078e017825a5d
5
5
  SHA512:
6
- metadata.gz: 706fe8b5a088ad6d737dbc1016c718ab4ae6368a772c5a7f728a4b19bba84f4f70960d457dfbd579bef90a0b0247cacfba88cb6c9bc73b1fc29c63296eb68cd7
7
- data.tar.gz: fed0df22ab89639ee90ca666bffa506f2395be4c5cf7dc7b99d4d00a44ab05953465d2749e3ab1ed07b9dc7fa6257873f8c31a1e2d83270464cb6f3a2cdea31c
6
+ metadata.gz: d738e244744e6dad3df385e4d65ac7afa22a0385a3e371f9a4b8ebd274d032d8d3cec8c8c757c9abb31df5e12a0f40beba72fa4df5a5d373b1916107c0c58b69
7
+ data.tar.gz: d489fe21546f871855abc3335f9517cc91babfbec766380633cce782798322c17fbf8dc01e08ee737038b766bca404de51df1da9d5472127bb0370d38126a7db
data/README.md CHANGED
@@ -53,6 +53,9 @@ $ gem install nexaas-async-collector
53
53
 
54
54
  # The parent class of all nexaas-async-collector controller
55
55
  config.parent_controller = "::ActionController::Base"
56
+
57
+ # The expiration of the data in seconds
58
+ config.expiration = 600
56
59
  end
57
60
  ```
58
61
 
@@ -74,7 +77,8 @@ end
74
77
  class_name: ModelService, # (required) name of the class
75
78
  class_method: :model_method, # (required) name of the class method responsible to generate data
76
79
  args: [arg1, arg2], # (optional) arguments to be passed to class method
77
- instrumentation_context: 'my.custom.instrumentation' # (optional) context of the instrumentation name. It will generate two instrumentation: 'my.custom.instrumentation.start' and 'my.custom.instrumentation.finish'
80
+ instrumentation_context: 'my.custom.instrumentation', # (optional) context of the instrumentation name. It will generate two instrumentation: 'my.custom.instrumentation.start' and 'my.custom.instrumentation.finish'
81
+ expiration: 180 # (optional) this local expiration will overwrite global expiration for this particular data generation
78
82
  }) %>
79
83
  ```
80
84
 
@@ -100,6 +104,10 @@ If you want to export something to `xls` file, for example:
100
104
 
101
105
  This will generate the spinner and it will redirect the user to download the file when it is ready.
102
106
 
107
+ ## Redis configuration
108
+
109
+ If you are sharing your Redis server between important information (e.g., Sidekiq data) and temporary information (e.g., `nexaas-async-collector` data), we suggest you to set the [`maxmemory-policy` eviction policy in Redis](https://redis.io/topics/lru-cache) to `volatile-lru` or `volatile-ttl`.
110
+
103
111
  ## Contributing
104
112
  Bug reports and pull requests are welcome on GitHub at [https://github.com/myfreecomm/nexaas-async-collector](https://github.com/myfreecomm/nexaas-async-collector). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
105
113
 
@@ -6,7 +6,7 @@
6
6
  window.location.href = '<%= async_resource_path(params[:id], format: @result.extension) %>';
7
7
  <% else %>
8
8
  $('#js-nexaas-async-collector-loading-<%= @unique_id %>').remove();
9
- $('#js-nexaas-async-collector-<%= @unique_id %>').parent().append("<%= escape_javascript(@result.content.html_safe) %>");
9
+ $('#js-nexaas-async-collector-<%= @unique_id %>').parent().append("<%= escape_javascript(@result.content.force_encoding('UTF-8').html_safe) %>");
10
10
  $('#js-nexaas-async-collector-<%= @unique_id %>').remove()
11
11
  $('#js-nexaas-async-collector-style-<%= @unique_id %>').remove()
12
12
  <% end %>
@@ -1,6 +1,6 @@
1
1
  require 'sidekiq'
2
2
  require "nexaas/async/collector/engine"
3
- require "nexaas/async/collector/in_memory_storage"
3
+ require "nexaas/async/collector/storage"
4
4
  require "nexaas/async/collector/result"
5
5
  require "nexaas/async/collector/persist"
6
6
 
@@ -32,6 +32,10 @@ module Nexaas
32
32
  mattr_accessor :parent_controller
33
33
  @@parent_controller = '::ActionController::Base'
34
34
 
35
+ # Sets expiration (in seconds) for content in database
36
+ mattr_accessor :expiration
37
+ @@expiration = 600 # 10 minutes
38
+
35
39
  def self.configure
36
40
  yield self
37
41
  end
@@ -2,27 +2,35 @@ module Nexaas
2
2
  module Async
3
3
  module Collector
4
4
  class Persist
5
- class << self
6
- def save(opts={})
7
- opts = opts.with_indifferent_access
8
- content = content_in_json(opts)
9
- storage.set(opts[:collect_id], content)
10
- end
11
5
 
12
- private
6
+ attr_reader :opts, :storage
13
7
 
14
- def content_in_json(opts)
15
- {
16
- 'scope_id' => opts[:scope_id],
17
- 'content' => (opts[:content] ? Base64.encode64(opts[:content].to_s) : nil),
18
- 'file' => opts[:file]
19
- }.to_json
20
- end
8
+ def initialize(opts={})
9
+ @opts = opts.with_indifferent_access
10
+ @storage = Storage.new
11
+ end
12
+
13
+ def self.save(opts={})
14
+ new(opts).save
15
+ end
21
16
 
17
+ def save
18
+ content = content_in_json(opts)
19
+ storage.set(opts[:collect_id], content, expiration)
20
+ end
21
+
22
+ private
23
+
24
+ def content_in_json(opts)
25
+ {
26
+ 'scope_id' => opts[:scope_id],
27
+ 'content' => (opts[:content] ? Base64.encode64(opts[:content].to_s) : nil),
28
+ 'file' => opts[:file]
29
+ }.to_json
30
+ end
22
31
 
23
- def storage
24
- InMemoryStorage.new
25
- end
32
+ def expiration
33
+ opts[:expiration] || Nexaas::Async::Collector.expiration
26
34
  end
27
35
  end
28
36
  end
@@ -11,11 +11,12 @@ module Nexaas
11
11
  module Collector
12
12
  class Result
13
13
 
14
- attr_reader :scope_id, :id, :object
14
+ attr_reader :scope_id, :id, :object, :storage
15
15
 
16
16
  def initialize(scope_id, id)
17
17
  @scope_id = scope_id
18
18
  @id = id
19
+ @storage = Storage.new
19
20
  end
20
21
 
21
22
  def content
@@ -44,10 +45,6 @@ module Nexaas
44
45
 
45
46
  private
46
47
 
47
- def storage
48
- @storage ||= InMemoryStorage.new
49
- end
50
-
51
48
  def object
52
49
  return @object if @object
53
50
  @_object = storage.get(id)
@@ -1,7 +1,7 @@
1
1
  module Nexaas
2
2
  module Async
3
3
  module Collector
4
- class InMemoryStorage
4
+ class Storage
5
5
 
6
6
  def get(key)
7
7
  Sidekiq.redis_pool.with do |connection|
@@ -9,11 +9,13 @@ module Nexaas
9
9
  end
10
10
  end
11
11
 
12
- def set(key, value, expiration=nil)
12
+ def set(key, value, expiration)
13
13
  Sidekiq.redis_pool.with do |connection|
14
14
  key = namespaced_key(key)
15
- connection.set(key, value)
16
- connection.expire(key, expiration) if expiration
15
+ connection.multi do
16
+ connection.set(key, value)
17
+ connection.expire(key, expiration)
18
+ end
17
19
  end
18
20
  end
19
21
 
@@ -1,7 +1,7 @@
1
1
  module Nexaas
2
2
  module Async
3
3
  module Collector
4
- VERSION = '3.2.0'
4
+ VERSION = '3.3.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexaas-async-collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Hertz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -151,9 +151,9 @@ files:
151
151
  - config/routes.rb
152
152
  - lib/nexaas/async/collector.rb
153
153
  - lib/nexaas/async/collector/engine.rb
154
- - lib/nexaas/async/collector/in_memory_storage.rb
155
154
  - lib/nexaas/async/collector/persist.rb
156
155
  - lib/nexaas/async/collector/result.rb
156
+ - lib/nexaas/async/collector/storage.rb
157
157
  - lib/nexaas/async/collector/version.rb
158
158
  homepage: https://github.com/myfreecomm/nexaas-async-collector
159
159
  licenses: