asynchronic 0.3.1 → 1.0.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: 132090d5e2432b8ac85802c8e1f71e3fba27fdf2
4
- data.tar.gz: fedfefdfee7fd6b3efdaeb83e659d92b421b33e9
3
+ metadata.gz: f1f6b6846abc0d662921131cdab188869fa36354
4
+ data.tar.gz: abaa211fac95e8fdd69795859341fb57d09547b4
5
5
  SHA512:
6
- metadata.gz: 2a34b079585ea34778d899b6da45f31e3a3164275eb39104fb04193f713c65efdb9da20a1c5a4310b771ed5fc95e72b378c89c05c4c3748680bd26fdbdd7c863
7
- data.tar.gz: cc12c442dcb63c80ea024de6660784b0f1521c201006fbe2a7a77a500384098f71a83805dd56dd652f07f476c5283cdfd641532a4f19a6a82a89d708466fc75e
6
+ metadata.gz: f484b72c6ed24f16b6633fe42b63ffecdcb9d1bcbce4345a62980b648233a5f76abaf0bd2ecbb534500645609a1d856e4169ba3d7d4fa7a2ba2036e05611a071
7
+ data.tar.gz: 674e42cba4808664ea3d5e006d2737e813c28a5a348de533bbcaf18606200b2d3cf5a2a357bf4d1102f0212018caa782d54cdc55df41f5c3330b6cf00311d445
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ Rake::TestTask.new(:spec) do |t|
9
9
  end
10
10
 
11
11
  task :console do
12
- require 'pry'
12
+ require 'pry-nav'
13
13
  require 'asynchronic'
14
14
  ARGV.clear
15
15
  Pry.start
data/asynchronic.gemspec CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'minitest-colorin', '~> 0.1'
30
30
  spec.add_development_dependency 'minitest-great_expectations', '~> 0.0'
31
31
  spec.add_development_dependency 'simplecov'
32
- spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'pry-nav'
33
33
  end
data/lib/asynchronic.rb CHANGED
@@ -17,7 +17,7 @@ module Asynchronic
17
17
  attr_config :data_store, DataStore::InMemory.new
18
18
  attr_config :logger, Logger.new($stdout)
19
19
 
20
- WAITING_TO_RETRY = 30
20
+ RETRY_TIMEOUT = 30
21
21
 
22
22
  def self.environment
23
23
  Environment.new queue_engine, data_store
@@ -36,7 +36,7 @@ module Asynchronic
36
36
  result = yield
37
37
  rescue Exception => ex
38
38
  logger.info(a_class) { "Retrying #{message}. ERROR: #{ex.message}" }
39
- sleep WAITING_TO_RETRY
39
+ sleep RETRY_TIMEOUT
40
40
  retry
41
41
  end
42
42
  result
@@ -26,7 +26,9 @@ module Asynchronic
26
26
  @hash.keys.map { |k| Key.new k }
27
27
  end
28
28
 
29
- alias_method :connection, :object_id
29
+ def connection_args
30
+ [object_id]
31
+ end
30
32
 
31
33
  def self.connect(object_id)
32
34
  connections[object_id]
@@ -4,7 +4,7 @@ module Asynchronic
4
4
 
5
5
  def initialize(data_store, key)
6
6
  @data_store_class = data_store.class
7
- @data_store_connection = data_store.connection
7
+ @data_store_connection_args = data_store.connection_args
8
8
  @key = key
9
9
  end
10
10
 
@@ -14,11 +14,11 @@ module Asynchronic
14
14
  end
15
15
 
16
16
  def inspect
17
- "#<#{proxy_class} @data_store_class=#{@data_store_class} @data_store_connection=#{@data_store_connection} @key=#{@key}>"
17
+ "#<#{proxy_class} @data_store_class=#{@data_store_class} @data_store_connection_args=#{@data_store_connection_args} @key=#{@key}>"
18
18
  end
19
19
 
20
20
  def data_store
21
- @data_store_class.connect @data_store_connection
21
+ @data_store_class.connect *@data_store_connection_args
22
22
  end
23
23
 
24
24
  def to_value
@@ -4,12 +4,13 @@ module Asynchronic
4
4
 
5
5
  include Helper
6
6
 
7
- def initialize(*args)
7
+ def initialize(scope, *args)
8
+ @scope = Key.new scope
8
9
  @connection = ::Redis.new *args
9
10
  end
10
11
 
11
12
  def [](key)
12
- value = @connection.get key.to_s
13
+ value = @connection.get @scope[key]
13
14
  value ? Marshal.load(value) : nil
14
15
  rescue => ex
15
16
  Asynchronic.logger.warn('Asynchronic') { ex.message }
@@ -17,23 +18,23 @@ module Asynchronic
17
18
  end
18
19
 
19
20
  def []=(key, value)
20
- @connection.set key.to_s, Marshal.dump(value)
21
+ @connection.set @scope[key], Marshal.dump(value)
21
22
  end
22
23
 
23
24
  def delete(key)
24
- @connection.del key.to_s
25
+ @connection.del @scope[key]
25
26
  end
26
27
 
27
28
  def keys
28
- @connection.keys.map { |k| Key.new k }
29
+ @connection.keys(@scope['*']).map { |k| Key.new(k).remove_first }
29
30
  end
30
31
 
31
- def connection
32
- @connection.client.options
32
+ def connection_args
33
+ [@scope, @connection.client.options]
33
34
  end
34
35
 
35
- def self.connect(options)
36
- new options
36
+ def self.connect(*args)
37
+ new *args
37
38
  end
38
39
 
39
40
  end
@@ -30,17 +30,19 @@ module Asynchronic
30
30
  map { |k| Key.new(k).remove_first @scope.sections.count }
31
31
  end
32
32
 
33
- def connection
34
- {
35
- data_store_class: @data_store.class,
36
- data_store_connection: @data_store.connection,
37
- scope: @scope
38
- }
39
- end
40
-
41
- def self.connect(options)
42
- data_store = options[:data_store_class].connect options[:data_store_connection]
43
- new data_store, options[:scope]
33
+ def connection_args
34
+ [
35
+ {
36
+ data_store_class: @data_store.class,
37
+ data_store_connection_args: @data_store.connection_args,
38
+ scope: @scope
39
+ }
40
+ ]
41
+ end
42
+
43
+ def self.connect(*args)
44
+ data_store = args[0][:data_store_class].connect *args[0][:data_store_connection_args]
45
+ new data_store, args[0][:scope]
44
46
  end
45
47
 
46
48
  def to_s
@@ -6,7 +6,7 @@ module Asynchronic
6
6
 
7
7
  def initialize(queue_engine, data_store)
8
8
  @queue_engine = queue_engine
9
- @data_store = data_store.scoped :asynchronic
9
+ @data_store = data_store
10
10
  end
11
11
 
12
12
  def queue(name)
@@ -1,3 +1,3 @@
1
1
  module Asynchronic
2
- VERSION = '0.3.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -32,7 +32,7 @@ module LazyValueExamples
32
32
 
33
33
  it 'Inspect' do
34
34
  value = lazy_value :key
35
- value.inspect.must_match /#<Asynchronic::DataStore::LazyValue @data_store_class=.+ @data_store_connection=.+ @key=key>/
35
+ value.inspect.must_match /#<Asynchronic::DataStore::LazyValue @data_store_class=.+ @data_store_connection_args=.+ @key=key>/
36
36
  end
37
37
 
38
38
  end
@@ -4,9 +4,9 @@ require_relative './lazy_value_examples'
4
4
 
5
5
  describe Asynchronic::DataStore::Redis do
6
6
 
7
- let(:data_store) { Asynchronic::DataStore::Redis.new }
7
+ let(:data_store) { Asynchronic::DataStore::Redis.new :asynchronic_test }
8
8
 
9
- before do
9
+ after do
10
10
  data_store.clear
11
11
  end
12
12
 
data/spec/facade_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'minitest_helper'
2
2
 
3
3
  describe Asynchronic, 'Facade' do
4
4
 
5
- before do
5
+ after do
6
6
  Asynchronic.environment.data_store.clear
7
7
  Asynchronic.environment.queue_engine.clear
8
8
  end
@@ -26,7 +26,7 @@ describe Asynchronic, 'Facade' do
26
26
  it 'Environment' do
27
27
  Asynchronic.environment.tap do |env|
28
28
  env.queue_engine.must_equal Asynchronic.queue_engine
29
- env.data_store.connection.must_equal Asynchronic.data_store.scoped(:asynchronic).connection
29
+ env.data_store.must_equal Asynchronic.data_store
30
30
  end
31
31
  end
32
32
 
@@ -5,6 +5,7 @@ require 'minitest/colorin'
5
5
  require 'minitest/great_expectations'
6
6
  require 'jobs'
7
7
  require 'expectations'
8
+ require 'pry-nav'
8
9
 
9
10
  class Module
10
11
  include Minitest::Spec::DSL
@@ -16,11 +17,6 @@ class Minitest::Spec
16
17
  before do
17
18
  Asynchronic.restore_default_configuration
18
19
  end
19
-
20
- after do
21
- Asynchronic::DataStore::Redis.new.clear
22
- Asynchronic::QueueEngine::Ost.new.clear
23
- end
24
20
  end
25
21
 
26
22
  module Asynchronic::DataStore::Helper
@@ -4,10 +4,10 @@ require_relative './life_cycle_examples.rb'
4
4
  describe Asynchronic::Process, 'Life cycle - Redis' do
5
5
 
6
6
  let(:queue_engine) { Asynchronic::QueueEngine::Ost.new }
7
- let(:data_store) { Asynchronic::DataStore::Redis.new }
7
+ let(:data_store) { Asynchronic::DataStore::Redis.new :asynchronic_test }
8
8
 
9
- before do
10
- Redis.current.flushdb
9
+ after do
10
+ data_store.clear
11
11
  end
12
12
 
13
13
  include LifeCycleExamples
@@ -4,9 +4,9 @@ require_relative './worker_examples'
4
4
  describe Asynchronic::Worker, 'Redis' do
5
5
 
6
6
  let(:queue_engine) { Asynchronic::QueueEngine::Ost.new }
7
- let(:data_store) { Asynchronic::DataStore::Redis.new }
7
+ let(:data_store) { Asynchronic::DataStore::Redis.new :asynchronic_test}
8
8
 
9
- before do
9
+ after do
10
10
  data_store.clear
11
11
  queue_engine.clear
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2016-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: pry
154
+ name: pry-nav
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '>='