seamule 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/seamule-server +26 -0
- data/bin/setup +7 -0
- data/lib/seamule.rb +110 -0
- data/lib/seamule/backend.rb +46 -0
- data/lib/seamule/encoder.rb +23 -0
- data/lib/seamule/job.rb +108 -0
- data/lib/seamule/json_encoder.rb +20 -0
- data/lib/seamule/queue.rb +42 -0
- data/lib/seamule/server.rb +60 -0
- data/lib/seamule/version.rb +3 -0
- data/seamule.gemspec +31 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a6dbd88d8473c2f609d7e913bb1a80b05bb787df
|
4
|
+
data.tar.gz: 57c3ccbeadf9ac5742ebaf029ff5d0be2df88c37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad351067d1a19a662b00466766ebee4ff1b813c7c6969d2f280a8d1904eb3a16f9083d8cac98d1fb6fdca014731acd7b6b8624b9b375d3c4ab38c06406a46a27
|
7
|
+
data.tar.gz: 5466bd08adca0404a70772cff0bd79126feaf4919534a0286e1bd60a2cbdfea2429b5e00aa8f03c858ade12995568ee5706dec557f242eeedc7c549bb3d2747c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Pablo Cárdenas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# SeaMule
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/seamule`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'seamule'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install seamule
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/seamule. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "seamule"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/seamule-server
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
begin
|
5
|
+
require 'vegas'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'vegas'
|
9
|
+
end
|
10
|
+
require 'seamule/server'
|
11
|
+
|
12
|
+
Vegas::Runner.new(SeaMule::Server, 'seamule-server', {
|
13
|
+
:before_run => lambda {|v|
|
14
|
+
path = (ENV['SEAMULE_CONFIG'] || v.args.first)
|
15
|
+
load path.to_s.strip if path
|
16
|
+
}
|
17
|
+
}) do |runner, opts, app|
|
18
|
+
opts.on('-N NAMESPACE', "--namespace NAMESPACE", "set the Redis namespace") {|namespace|
|
19
|
+
runner.logger.info "Using Redis namespace '#{namespace}'"
|
20
|
+
SeaMule.redis.namespace = namespace
|
21
|
+
}
|
22
|
+
opts.on('-r redis-connection', "--redis redis-connection", "set the Redis connection string") {|redis_conf|
|
23
|
+
runner.logger.info "Using Redis connection '#{redis_conf}'"
|
24
|
+
SeaMule.redis = redis_conf
|
25
|
+
}
|
26
|
+
end
|
data/bin/setup
ADDED
data/lib/seamule.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'mono_logger'
|
3
|
+
|
4
|
+
require 'seamule/version'
|
5
|
+
require 'seamule/backend'
|
6
|
+
require 'seamule/encoder'
|
7
|
+
require 'seamule/json_encoder'
|
8
|
+
require 'seamule/job'
|
9
|
+
require 'seamule/server'
|
10
|
+
require 'seamule/queue'
|
11
|
+
|
12
|
+
require 'forwardable'
|
13
|
+
|
14
|
+
module SeaMule
|
15
|
+
extend Forwardable
|
16
|
+
extend self
|
17
|
+
|
18
|
+
QUEUES = %w(pending active done).freeze
|
19
|
+
|
20
|
+
DEFAULT_QUEUE = QUEUES.first.freeze
|
21
|
+
|
22
|
+
attr_reader :redis
|
23
|
+
|
24
|
+
attr_writer :coder
|
25
|
+
|
26
|
+
attr_accessor :logger
|
27
|
+
|
28
|
+
def encode(object)
|
29
|
+
coder.encode(object)
|
30
|
+
end
|
31
|
+
|
32
|
+
def decode(object)
|
33
|
+
coder.decode(object)
|
34
|
+
end
|
35
|
+
|
36
|
+
def backend
|
37
|
+
@backend ||= Backend.new(@redis, SeaMule.logger)
|
38
|
+
end
|
39
|
+
|
40
|
+
def redis=(server)
|
41
|
+
@redis = Backend.connect(server) unless server.nil?
|
42
|
+
@backend = Backend.new(@redis, SeaMule.logger)
|
43
|
+
create_queues
|
44
|
+
@redis
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_queues
|
48
|
+
@queues = {}
|
49
|
+
QUEUES.each do |queue_name|
|
50
|
+
@queues[queue_name] = SeaMule::Queue.new(queue_name, @redis)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def coder
|
55
|
+
@coder ||= JsonEncoder.new
|
56
|
+
end
|
57
|
+
|
58
|
+
def push(queue, item)
|
59
|
+
queue(queue) << item
|
60
|
+
end
|
61
|
+
|
62
|
+
def pop(queue, id = nil)
|
63
|
+
queue(queue).pop(id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def pop_and_push(from_queue, to_queue)
|
67
|
+
job = pop(from_queue)
|
68
|
+
push(to_queue, job) if job
|
69
|
+
job
|
70
|
+
end
|
71
|
+
|
72
|
+
def size(queue)
|
73
|
+
queue(queue).size
|
74
|
+
end
|
75
|
+
|
76
|
+
def queues
|
77
|
+
Array(backend.store.smembers(:queues))
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_queue(queue)
|
81
|
+
queue(queue).destroy
|
82
|
+
@queues.delete(queue.to_s)
|
83
|
+
end
|
84
|
+
|
85
|
+
def queue(name)
|
86
|
+
@queues[name.to_s]
|
87
|
+
end
|
88
|
+
|
89
|
+
def enqueue(klass, payload, meta = nil)
|
90
|
+
enqueue_to(DEFAULT_QUEUE, klass, payload, meta)
|
91
|
+
end
|
92
|
+
|
93
|
+
def enqueue_to(queue, klass, payload, meta)
|
94
|
+
Job.create(queue, klass, payload, meta)
|
95
|
+
end
|
96
|
+
|
97
|
+
def dequeue(queue, klass: nil, payload: nil, id: nil)
|
98
|
+
Job.destroy(queue, klass: klass, payload: payload, id: id)
|
99
|
+
end
|
100
|
+
|
101
|
+
def queued(queue, klass: nil, payload: nil, id: nil)
|
102
|
+
Job.queued(queue, klass: klass, payload: payload, id: id)
|
103
|
+
end
|
104
|
+
|
105
|
+
def keys
|
106
|
+
backend.store.keys('*')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
SeaMule.logger = MonoLogger.new(STDOUT)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'redis-namespace'
|
2
|
+
|
3
|
+
module SeaMule
|
4
|
+
class Backend
|
5
|
+
attr_reader :store
|
6
|
+
|
7
|
+
attr_reader :logger
|
8
|
+
|
9
|
+
def initialize(store, logger)
|
10
|
+
@store = store
|
11
|
+
@logger = logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.connect(server)
|
15
|
+
case server
|
16
|
+
when String
|
17
|
+
redis = connect_to(server)
|
18
|
+
Redis::Namespace.new(:seamule, redis: redis)
|
19
|
+
when Hash
|
20
|
+
Redis::Namespace.new(:seamule, redis: Redis.new(server))
|
21
|
+
else
|
22
|
+
raise ArgumentError, "Invalid Server: #{server.inspect}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.connect_to(server)
|
27
|
+
Redis.connect(url: server, :thread_safe => true)
|
28
|
+
end
|
29
|
+
|
30
|
+
MAX_RECONNECT_ATTEMPTS = 3
|
31
|
+
|
32
|
+
def reconnect
|
33
|
+
store.client.reconnect
|
34
|
+
rescue Redis::BaseConnectionError
|
35
|
+
tries ||= 0
|
36
|
+
if (tries += 1) < MAX_RECONNECT_ATTEMPTS
|
37
|
+
logger.info "Error reconnecting to Redis; retrying"
|
38
|
+
Kernel.sleep(tries)
|
39
|
+
retry
|
40
|
+
else
|
41
|
+
logger.info "Error reconnecting to Redis; quitting"
|
42
|
+
raise ConnectionError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SeaMule
|
2
|
+
class EncodeException < StandardError; end
|
3
|
+
|
4
|
+
class DecodeException < StandardError; end
|
5
|
+
|
6
|
+
class Encoder
|
7
|
+
def encode(object)
|
8
|
+
raise EncodeException
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump(object)
|
12
|
+
encode(object)
|
13
|
+
end
|
14
|
+
|
15
|
+
def decode(object)
|
16
|
+
raise DecodeException
|
17
|
+
end
|
18
|
+
|
19
|
+
def load(object)
|
20
|
+
decode(object)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/seamule/job.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module SeaMule
|
4
|
+
class Job
|
5
|
+
attr_reader :id
|
6
|
+
|
7
|
+
attr_reader :callback_class_name
|
8
|
+
|
9
|
+
attr_reader :meta
|
10
|
+
|
11
|
+
attr_reader :queue
|
12
|
+
|
13
|
+
attr_reader :payload
|
14
|
+
|
15
|
+
attr_accessor :result
|
16
|
+
|
17
|
+
def initialize(queue, content)
|
18
|
+
@queue = queue
|
19
|
+
@payload = content['payload']
|
20
|
+
@meta = content['meta']
|
21
|
+
@id = content['id']
|
22
|
+
@callback_class_name = content['class']
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.create(queue, klass, payload, meta)
|
26
|
+
SeaMule.push(queue, class: klass.to_s, payload: payload, meta: meta, id: SecureRandom.hex)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.destroy(queue, klass: nil, payload: nil, id: nil)
|
30
|
+
coder = SeaMule.coder
|
31
|
+
redis = SeaMule.backend.store
|
32
|
+
klass = klass.to_s
|
33
|
+
|
34
|
+
destroyed_count = process_queue(queue, coder, redis, klass, payload, id) do |decoded, new_queue, temp_queue, requeue_queue|
|
35
|
+
redis.del(temp_queue).to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
destroyed_count.inject(0, :+)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.queued(queue, klass: nil, payload: nil, id: nil)
|
42
|
+
coder = SeaMule.coder
|
43
|
+
redis = SeaMule.backend.store
|
44
|
+
klass = klass.to_s
|
45
|
+
|
46
|
+
jobs = process_queue(queue, coder, redis, klass, payload, id) do |decoded, _new_queue, temp_queue, requeue_queue|
|
47
|
+
redis.rpoplpush(temp_queue, requeue_queue)
|
48
|
+
new(queue, decoded)
|
49
|
+
end
|
50
|
+
|
51
|
+
jobs
|
52
|
+
end
|
53
|
+
|
54
|
+
def perform
|
55
|
+
object = callback_class.new
|
56
|
+
object.perform(id, meta, payload, result)
|
57
|
+
end
|
58
|
+
|
59
|
+
def callback_class
|
60
|
+
@callback_class ||= callback_class_name.to_s.constantize
|
61
|
+
end
|
62
|
+
|
63
|
+
def to_h
|
64
|
+
{
|
65
|
+
:queue => queue,
|
66
|
+
:run_at => Time.now.utc.iso8601,
|
67
|
+
:payload => payload
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def inspect
|
72
|
+
"Job @#{@queue} | #{@callback_class_name} | #{@meta.inspect} | #{@payload.inspect}"
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def ==(other)
|
77
|
+
queue == other.queue &&
|
78
|
+
callback_class == other.callback_class &&
|
79
|
+
meta == other.meta &&
|
80
|
+
payload == other.payload
|
81
|
+
end
|
82
|
+
|
83
|
+
protected
|
84
|
+
|
85
|
+
def self.process_queue(queue, coder, redis, klass, payload, id)
|
86
|
+
return_array = []
|
87
|
+
new_queue = "queue:#{queue}"
|
88
|
+
temp_queue = "queue:#{queue}:temp:#{Time.now.to_i}"
|
89
|
+
requeue_queue = "#{temp_queue}:requeue"
|
90
|
+
|
91
|
+
while string = redis.rpoplpush(new_queue, temp_queue)
|
92
|
+
decoded = coder.decode(string)
|
93
|
+
if decoded['id'] == id || (decoded['class'] == klass && (payload.empty? || decoded['payload'] == payload))
|
94
|
+
return_array.unshift(yield decoded, new_queue, temp_queue, requeue_queue)
|
95
|
+
else
|
96
|
+
redis.rpoplpush(temp_queue, requeue_queue)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
push_queue(redis, requeue_queue, new_queue)
|
100
|
+
|
101
|
+
return_array
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.push_queue(redis, requeue_queue, queue)
|
105
|
+
loop { redis.rpoplpush(requeue_queue, queue) or break }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'seamule/encoder'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module SeaMule
|
5
|
+
class JsonEncoder < Encoder
|
6
|
+
def encode(object)
|
7
|
+
JSON.dump(object)
|
8
|
+
end
|
9
|
+
|
10
|
+
def decode(object)
|
11
|
+
return unless object
|
12
|
+
|
13
|
+
begin
|
14
|
+
JSON.load(object)
|
15
|
+
rescue ::JSON::JSONError => e
|
16
|
+
raise SeaMule::DecodeException, e.message, e.backtrace
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'redis'
|
2
|
+
|
3
|
+
module SeaMule
|
4
|
+
class Queue
|
5
|
+
attr_reader :name, :redis_name
|
6
|
+
|
7
|
+
def initialize(name, redis)
|
8
|
+
super()
|
9
|
+
@name = name
|
10
|
+
@redis_name = "queue:#{@name}"
|
11
|
+
@redis = redis
|
12
|
+
@redis.sadd(:queues, @name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def push(object)
|
16
|
+
begin
|
17
|
+
encoded_object = SeaMule.encode(object)
|
18
|
+
rescue SeaMule::EncodeException => e
|
19
|
+
SeaMule.logger.error "Invalid UTF-8 character in job: #{e.message}"
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
@redis.rpush(@redis_name, encoded_object)
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :<< :push
|
27
|
+
|
28
|
+
def pop(id = nil)
|
29
|
+
SeaMule.decode(@redis.lpop(@redis_name))
|
30
|
+
end
|
31
|
+
|
32
|
+
def length
|
33
|
+
@redis.llen(@redis_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
alias :size :length
|
37
|
+
|
38
|
+
def empty?
|
39
|
+
size == 0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'seamule'
|
3
|
+
|
4
|
+
if defined? Encoding
|
5
|
+
Encoding.default_external = Encoding::UTF_8
|
6
|
+
end
|
7
|
+
|
8
|
+
module SeaMule
|
9
|
+
class Server < Sinatra::Base
|
10
|
+
set :static, true
|
11
|
+
|
12
|
+
def render_json(object)
|
13
|
+
response['Cache-Control'] = 'max-age=0, private, must-revalidate'
|
14
|
+
content_type :json
|
15
|
+
begin
|
16
|
+
object.to_json
|
17
|
+
rescue Errno::ECONNREFUSED
|
18
|
+
status 500
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/jobs.json' do
|
23
|
+
render_json([])
|
24
|
+
end
|
25
|
+
|
26
|
+
post '/jobs.json' do
|
27
|
+
job = SeaMule.pop_and_push(:pending, :active)
|
28
|
+
if job
|
29
|
+
render_json(job)
|
30
|
+
else
|
31
|
+
unprocessable_entity
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
patch '/jobs/:id.json' do
|
36
|
+
job = SeaMule.queued(:active, id: params[:id]).first
|
37
|
+
if job
|
38
|
+
job.result = read_json
|
39
|
+
SeaMule.dequeue(:active, id: params[:id])
|
40
|
+
SeaMule.push(:done, job)
|
41
|
+
render_json(params.to_json)
|
42
|
+
job.perform
|
43
|
+
else
|
44
|
+
unprocessable_entity
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def not_authorized
|
49
|
+
status 403
|
50
|
+
end
|
51
|
+
|
52
|
+
def unprocessable_entity
|
53
|
+
status 422
|
54
|
+
end
|
55
|
+
|
56
|
+
def read_json
|
57
|
+
JSON.parse(request.env['rack.input'].read)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/seamule.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'seamule/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'seamule'
|
8
|
+
spec.version = SeaMule::VERSION
|
9
|
+
spec.authors = ['Pablo Cárdenas']
|
10
|
+
spec.email = ['pcardenasoliveros@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{SeaMule is a Redis-backed Ruby library for creating jobs assigning them to clients and reducing them later}
|
13
|
+
spec.description = %q{SeaMule is a Redis-backed Ruby library for creating jobs assigning them to clients and reducing them later}
|
14
|
+
spec.homepage = 'https://github.com/pablo-co/seamule'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = ['seamule-server']
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'minitest'
|
25
|
+
|
26
|
+
spec.add_dependency 'multi_json', '~> 1.11.2'
|
27
|
+
spec.add_dependency 'sinatra', '>= 0.9.2'
|
28
|
+
spec.add_dependency 'redis-namespace', '~> 1.5.1'
|
29
|
+
spec.add_dependency 'vegas', '~> 0.1.2'
|
30
|
+
spec.add_dependency 'mono_logger', '>= 1.1.0'
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seamule
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pablo Cárdenas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.11.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.11.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis-namespace
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.5.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.5.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: vegas
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.1.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.1.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mono_logger
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.1.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.1.0
|
125
|
+
description: SeaMule is a Redis-backed Ruby library for creating jobs assigning them
|
126
|
+
to clients and reducing them later
|
127
|
+
email:
|
128
|
+
- pcardenasoliveros@gmail.com
|
129
|
+
executables:
|
130
|
+
- seamule-server
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- ".travis.yml"
|
136
|
+
- CODE_OF_CONDUCT.md
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/console
|
142
|
+
- bin/seamule-server
|
143
|
+
- bin/setup
|
144
|
+
- lib/seamule.rb
|
145
|
+
- lib/seamule/backend.rb
|
146
|
+
- lib/seamule/encoder.rb
|
147
|
+
- lib/seamule/job.rb
|
148
|
+
- lib/seamule/json_encoder.rb
|
149
|
+
- lib/seamule/queue.rb
|
150
|
+
- lib/seamule/server.rb
|
151
|
+
- lib/seamule/version.rb
|
152
|
+
- seamule.gemspec
|
153
|
+
homepage: https://github.com/pablo-co/seamule
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.8
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: SeaMule is a Redis-backed Ruby library for creating jobs assigning them to
|
177
|
+
clients and reducing them later
|
178
|
+
test_files: []
|