pallets 0.1.0 → 0.2.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
- SHA256:
3
- metadata.gz: fd28e870c825c99c372243b13d14574d3d6ec36b83bf031230938fe0121caeae
4
- data.tar.gz: f9ad65469c6d58510c01ed22591e875c941a3609eaff4191b1156ee6215a1748
2
+ SHA1:
3
+ metadata.gz: 388f932d85cba341084169563b80c6d18a0959f5
4
+ data.tar.gz: 04bbaa05f08caf6e53eaf632c13ee481abec2399
5
5
  SHA512:
6
- metadata.gz: 33aaa7382095bda19a78c7baa5bfab9cc2246aa3b8b309706b54ca381f34f06df2e0196a04b110c6daee6b5720894ba12ddadd89e952b947014dbb0df85ed8df
7
- data.tar.gz: 69a052b8663b578757bcda235a2d46159cc74871c84efe319cbb5da1aaba3992d5bbc84261e65e8b0cd51e95f3022a67dc35dc27e696f6b648febc2054fe0e3a
6
+ metadata.gz: cde6012d314a8c543cb63a156f2a667cb8b926c9a18c18c89b5c52bed6c680c07e9f8235a9f4b37a36dba17031f8923f6d445a9f019bce4e7c97757954242409
7
+ data.tar.gz: 9493181596052789e359bdf5e079e23707f740bd9e97b6ebc56ab0974f85f528c4fbc905bb8695c61cfb6b6e1f77ce2b675c0213a9f6f39251e4b95dad7f71fe
data/README.md CHANGED
@@ -37,7 +37,7 @@ That's basically it! Curious for more? Read on!
37
37
  * reliable
38
38
  * retries failed tasks
39
39
  * Redis backend out of the box
40
- * JSON serializer out of the box
40
+ * JSON and msgpack serializers out of the box
41
41
  * beautiful DSL
42
42
  * convention over configuration
43
43
  * thoroughly tested
data/lib/pallets.rb CHANGED
@@ -11,12 +11,14 @@ require 'pallets/pool'
11
11
  require 'pallets/scheduler'
12
12
  require 'pallets/serializers/base'
13
13
  require 'pallets/serializers/json'
14
+ require 'pallets/serializers/msgpack'
14
15
  require 'pallets/task'
16
+ require 'pallets/util'
15
17
  require 'pallets/worker'
16
18
  require 'pallets/workflow'
17
19
 
18
- require 'active_support/inflector'
19
20
  require 'logger'
21
+ require 'securerandom'
20
22
 
21
23
  module Pallets
22
24
  def self.configuration
@@ -29,7 +31,7 @@ module Pallets
29
31
 
30
32
  def self.backend
31
33
  @backend ||= begin
32
- cls = "Pallets::Backends::#{configuration.backend.capitalize}".constantize
34
+ cls = Pallets::Util.constantize("Pallets::Backends::#{configuration.backend.capitalize}")
33
35
  cls.new(
34
36
  namespace: configuration.namespace,
35
37
  blocking_timeout: configuration.blocking_timeout,
@@ -42,7 +44,7 @@ module Pallets
42
44
 
43
45
  def self.serializer
44
46
  @serializer ||= begin
45
- cls = "Pallets::Serializers::#{configuration.serializer.capitalize}".constantize
47
+ cls = Pallets::Util.constantize("Pallets::Serializers::#{configuration.serializer.capitalize}")
46
48
  cls.new
47
49
  end
48
50
  end
@@ -1,10 +1,7 @@
1
- require 'active_support'
2
-
3
1
  module Pallets
4
2
  module DSL
5
3
  module Workflow
6
- def task(*args, &block)
7
- options = args.extract_options!
4
+ def task(*args, **options, &block)
8
5
  name, depends_on = if args.any?
9
6
  [args.first, options[:depends_on]]
10
7
  else
@@ -17,7 +14,7 @@ module Pallets
17
14
  dependencies = Array(depends_on).compact.map(&:to_sym)
18
15
  graph.add(name, dependencies)
19
16
 
20
- class_name = options[:class_name] || name.to_s.camelize
17
+ class_name = options[:class_name] || Pallets::Util.camelize(name)
21
18
  max_failures = options[:max_failures] || Pallets.configuration.max_failures
22
19
 
23
20
  task_config[name] = {
@@ -0,0 +1,15 @@
1
+ require 'msgpack'
2
+
3
+ module Pallets
4
+ module Serializers
5
+ class Msgpack
6
+ def dump(data)
7
+ MessagePack.pack(data)
8
+ end
9
+
10
+ def load(data)
11
+ MessagePack.unpack(data)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module Pallets
2
+ module Util
3
+ extend self
4
+
5
+ def camelize(str)
6
+ str.to_s.gsub(/(?:^|_)([a-z])/) { $1.upcase }
7
+ end
8
+
9
+ def constantize(str)
10
+ names = str.split('::')
11
+
12
+ # Raise the "usual" NameError
13
+ Object.const_get(str) if names.empty?
14
+
15
+ # Handle "::Const" cases
16
+ names.shift if names.first.empty?
17
+
18
+ names.inject(Object) do |constant, name|
19
+ if constant.const_defined?(name, false)
20
+ constant.const_get(name, false)
21
+ else
22
+ constant.const_missing(name)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Pallets
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -63,7 +63,7 @@ module Pallets
63
63
  return
64
64
  end
65
65
 
66
- task_class = job_hash["class_name"].constantize
66
+ task_class = Pallets::Util.constantize(job_hash["class_name"])
67
67
  task = task_class.new(job_hash["context"])
68
68
  begin
69
69
  task.run
data/pallets.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = ["pallets"]
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activesupport"
22
21
  spec.add_dependency "redis"
22
+ spec.add_dependency "msgpack"
23
23
  spec.add_development_dependency "bundler", "~> 1.11"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pallets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Horak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-29 00:00:00.000000000 Z
11
+ date: 2018-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: redis
28
+ name: msgpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -146,7 +146,9 @@ files:
146
146
  - lib/pallets/scheduler.rb
147
147
  - lib/pallets/serializers/base.rb
148
148
  - lib/pallets/serializers/json.rb
149
+ - lib/pallets/serializers/msgpack.rb
149
150
  - lib/pallets/task.rb
151
+ - lib/pallets/util.rb
150
152
  - lib/pallets/version.rb
151
153
  - lib/pallets/worker.rb
152
154
  - lib/pallets/workflow.rb
@@ -170,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
172
  version: '0'
171
173
  requirements: []
172
174
  rubyforge_project:
173
- rubygems_version: 2.7.7
175
+ rubygems_version: 2.6.14.1
174
176
  signing_key:
175
177
  specification_version: 4
176
178
  summary: Toy workflow engine, written in Ruby