warpcore 0.1.4 → 0.1.5

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: 64d39ad237b3b431d752615c8aa39cdd8d51c8cf
4
- data.tar.gz: 833178d0157e183c2b9ec1440705a7723c5f0caa
3
+ metadata.gz: 49d5997abb7a9c1c8329fec10bf2d19aa6aeae4b
4
+ data.tar.gz: 6e08ceef2a0f355be9cac56c68174146a3863afb
5
5
  SHA512:
6
- metadata.gz: b5e9dd10e1b7864584a4c6affc62030fb7a4bb18dc1dfd8bcef96e0daaeb9cb1b01512b5aecba526fd42507b6bd9480d2341d641ec4e340701d2110cc5b273d5
7
- data.tar.gz: 4f0a1fcb27a0cac559041192fc6f43abb618468d7a61a81adeef81d90854a1d028f5010e31866bf1c3ab291437596f943e30b05d311008e304072a5c1db879be
6
+ metadata.gz: 45ab49dbaf5614ff6bbbb6ece565b256066c895aad4f4fb083f293795f459b3eb5bcd1cc5ddb44cae3774cb06763cf11d0bd0ca5d5c2e1717a58cd30d5dce5ba
7
+ data.tar.gz: 00a4006ed3ce3eddac21f199ad3d26f428aaf1d4c0d5d1e02b872aa022c01f76b55a01dda3c185cc8c795e60c36fcf2c563a0e8239ccff07f74a2256b0c26955
data/lib/warpcore.rb CHANGED
@@ -7,6 +7,7 @@ require 'sucker_punch'
7
7
  require 'redis'
8
8
  require 'moneta'
9
9
  require 'dotenv'
10
+ require_relative 'warpcore/config'
10
11
  require_relative 'warpcore/cache'
11
12
  require_relative 'warpcore/dispatch'
12
13
  require_relative 'warpcore/sidekiq'
@@ -3,7 +3,7 @@ require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
 
5
5
  module WarpCore
6
- # cache helper
6
+
7
7
  def self.cache(key,opts = {})
8
8
  if block_given?
9
9
  WarpCore::Cache.get( key, opts, Proc.new )
@@ -12,6 +12,8 @@ module WarpCore
12
12
  end
13
13
  end
14
14
 
15
+ # A class helper to manage a Moneta cache store that can be used throughout the
16
+ # system.
15
17
  class Cache
16
18
  class << self
17
19
  attr_accessor :store
@@ -0,0 +1,32 @@
1
+ require 'open-uri'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+
5
+ module WarpCore
6
+ # Class provides a helper method to load
7
+ class Env
8
+ # Applies a remote JSON hash containing the ENV keys and values from a remote
9
+ # URL. Values from the JSON hash are only applied to the current ENV hash ONLY if
10
+ # it does not already have a value. Therefore local ENV values will take precedence
11
+ # over remote ones. By default, it uses the url in value in ENV['ENV_URL'].
12
+ # @param url [String] the remote url that responds with the JSON body.
13
+ # @return [Boolean] true if the JSON hash was found and applied successfully.
14
+ def self.load_url!(url = nil)
15
+ url ||= ENV["ENV_URL"]
16
+ if url.present?
17
+ begin
18
+ remote_config = JSON.load open( url )
19
+ remote_config.each do |key,value|
20
+ k = key.upcase
21
+ ENV[k] ||= value.to_s
22
+ end
23
+ return true
24
+ rescue => e
25
+ warn "[WarpCore::Config] Error loading config: #{url} (#{e})"
26
+ end
27
+ end
28
+ false
29
+ end
30
+
31
+ end
32
+ end
@@ -3,24 +3,29 @@ require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
 
5
5
  module WarpCore
6
-
6
+ # A class to support running blocks in a serial queue on a background thread.
7
7
  class SerialDispatchQueue
8
8
  include SuckerPunch::Job
9
9
  workers 1 # serial queue
10
-
10
+ # @!visibility private
11
11
  def perform(block = nil)
12
12
  block.call() if block.respond_to?(:call)
13
13
  end
14
14
  end
15
15
 
16
+ # A class to support running blocks in concurrent queue on a background thread.
16
17
  class ParallelDispatchQueue
17
18
  include SuckerPunch::Job
18
-
19
+ # @!visibility private
19
20
  def perform(block = nil)
20
21
  block.call() if block.respond_to?(:call)
21
22
  end
22
23
  end
23
24
 
25
+ # Helper method to run a block on a background thread.
26
+ # @param type [Symbol] the queue to use when dispatching the block.
27
+ # * :serial - use the {SerialDispatchQueue}
28
+ # * :parallel - use the {ParallelDispatchQueue}
24
29
  def self.async(type = :serial)
25
30
  raise "You need to pass a block to async." unless block_given?
26
31
  if type == :parallel
@@ -30,6 +35,10 @@ module WarpCore
30
35
  end
31
36
  end
32
37
 
38
+ # Helper method to run a block on a background thread.
39
+ # @param type (see WarpCore.async)
40
+ # * :serial - use the {SerialDispatchQueue}
41
+ # * :parallel - use the {ParallelDispatchQueue}
33
42
  def self.delay_by(seconds, type = :serial)
34
43
  raise "You need to pass a block to delay_by." unless block_given?
35
44
  if type == :parallel
@@ -3,7 +3,9 @@ require_relative 'dispatch'
3
3
 
4
4
  module Parse
5
5
  class Object
6
-
6
+ # Adds support for saving a Parse::Object instance in the background.
7
+ # If an exception is thrown, it is handled silently.
8
+ # @yield A block to call after the save has completed successfully
7
9
  def save_eventually
8
10
  block = block_given? ? Proc.new : nil
9
11
  WarpCore.async do
@@ -16,6 +18,11 @@ module Parse
16
18
  end
17
19
  end
18
20
 
21
+ # Same as {save_eventually}, but calls `save` on an object in the if it is
22
+ # new, otherwise it calls `update!`.
23
+ # If an exception is thrown, it is handled silently.
24
+ # @yield (see Parse::Object#save_eventually)
25
+ # @see #save_eventually
19
26
  def save_eventually!
20
27
  WarpCore.async do
21
28
  begin
@@ -5,10 +5,17 @@ require 'active_support/core_ext'
5
5
 
6
6
  module WarpCore
7
7
 
8
+ # @return [RedisPoolInstance] a usable redis instance shared by Sidekiq.
8
9
  def self.redis
9
10
  WarpCore::RedisPoolInstance.new
10
11
  end
11
12
 
13
+ # Asynchronously dispatch a Sidekiq worker with the provided arguments. This
14
+ # is equivalent to calling the worker directly with `perform_async`.
15
+ # @example
16
+ # WarpCore.dispatch 'Workers::MyWorker', argument1, argument2.....
17
+ # @param worker_name [String] the full class path of the worker (ex. `Workers::MyWorker`)
18
+ # @param args [Array] the arguments to pass to the worker.
12
19
  def self.dispatch(worker_name, *args)
13
20
  klass = worker_name.constantize
14
21
  if klass.respond_to?(:perform_async)
@@ -23,6 +30,13 @@ module WarpCore
23
30
  nil
24
31
  end
25
32
 
33
+ # Asynchronously dispatch a Sidekiq worker at a later time with the provided
34
+ # arguments. This is equivalent to calling the worker directly with `perform_in`.
35
+ # @example
36
+ # WarpCore.dispatch_in 'Workers::MyWorker', 10.seconds, argument1, argument2.....
37
+ # @param worker_name (see WarpCore.dispatch)
38
+ # @param args [Array] the arguments to pass to the worker. The first argument
39
+ # should be the amount of time to wait before dispatching the worker.
26
40
  def self.dispatch_in(worker_name, *args)
27
41
  klass = worker_name.constantize
28
42
  if klass.respond_to?(:perform_async)
@@ -37,6 +51,13 @@ module WarpCore
37
51
  nil
38
52
  end
39
53
 
54
+ # Synchronously dispatch a Sidekiq worker with the provided
55
+ # arguments. This is equivalent to instantiating the worker instance directly
56
+ # and calling `perform` on it.
57
+ # @example
58
+ # WarpCore.dispatch_sync 'Workers::MyWorker', argument1, argument2.....
59
+ # @param worker_name (see WarpCore.dispatch)
60
+ # @param args [Array] the arguments to pass to the worker.
40
61
  def self.dispatch_sync(worker_name, *args)
41
62
  klass = worker_name.constantize
42
63
  object = klass.new
@@ -52,19 +73,16 @@ module WarpCore
52
73
  nil
53
74
  end
54
75
 
55
- # Because +Sidekiq.redis+ requires passing a block,
56
- # we can't pass it straight to +Redis::Semaphore+.
57
- # This class simply delegates every method call to
58
- # the Sidekiq connection.
59
- # use RedisPoolInstance.new to get a shared redis connection
76
+ # This class simply delegates every method call to the Sidekiq redis connection.
77
+ # Use RedisPoolInstance.new to get a shared redis connection.
60
78
  class RedisPoolInstance
61
-
79
+ # @!visibility private
62
80
  def method_missing(meth, *args, &block)
63
81
  Sidekiq.redis do |connection|
64
82
  connection.send(meth, *args, &block)
65
83
  end
66
84
  end
67
-
85
+ # @!visibility private
68
86
  def respond_to_missing?(meth)
69
87
  Sidekiq.redis do |connection|
70
88
  connection.respond_to?(meth)
@@ -1,3 +1,6 @@
1
+ # This module provides a set of classes and components to build large scale, scalable
2
+ # and easier to maintain ruby-based applications with Parse.
1
3
  module WarpCore
2
- VERSION = "0.1.4"
4
+ # Version number
5
+ VERSION = "0.1.5"
3
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warpcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Persaud
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-06 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -200,6 +200,7 @@ extra_rdoc_files: []
200
200
  files:
201
201
  - lib/warpcore.rb
202
202
  - lib/warpcore/cache.rb
203
+ - lib/warpcore/config.rb
203
204
  - lib/warpcore/dispatch.rb
204
205
  - lib/warpcore/parse_stack.rb
205
206
  - lib/warpcore/sidekiq.rb