workiq 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/lib/workiq.rb +11 -0
- data/lib/workiq/middleware/chain.rb +11 -0
- data/lib/workiq/middleware/client.rb +11 -0
- data/lib/workiq/middleware/server.rb +15 -0
- data/lib/workiq/storage.rb +23 -0
- data/lib/workiq/version.rb +3 -0
- data/workiq.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Moustafa Badawy <moustafa@rubikal.com>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Workiq
|
2
|
+
|
3
|
+
Workiq adds a [Sidekiq](http://github.com/mperham/sidekiq) middleware to track a job worker status. Available status values are `:queued`, `:working`, `:complete`, and `:failed`
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'workiq'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install workiq
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
* Define your Sidekiq workers as normal. Check the [Sidekiq home page](http://mperham.github.com/sidekiq/) for details.
|
21
|
+
* Call the worker perform method
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
job_id = JobWorker.perform_async(*args)
|
25
|
+
```
|
26
|
+
|
27
|
+
OR
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
job_id = Model.delay.do_some_stuff(*args)
|
31
|
+
```
|
32
|
+
* Poll job status (`:queued`, `:working`, `:complete`, and `:failed`)
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
status = Workiq.status(job_id)
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/workiq.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "workiq/version"
|
2
|
+
require "workiq/storage"
|
3
|
+
require "workiq/middleware/client"
|
4
|
+
require "workiq/middleware/server"
|
5
|
+
require "workiq/middleware/chain"
|
6
|
+
|
7
|
+
module Workiq
|
8
|
+
def self.status(jid)
|
9
|
+
Workiq::Storage.read_field(jid, :status).to_sym
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Workiq
|
2
|
+
module Middleware
|
3
|
+
class Server
|
4
|
+
def call(worker, msg, queue)
|
5
|
+
jid = msg['jid']
|
6
|
+
Workiq::Storage.store_field jid, :status => :working
|
7
|
+
yield
|
8
|
+
Workiq::Storage.store_field jid, :status => :complete
|
9
|
+
rescue
|
10
|
+
Workiq::Storage.store_field jid, :status => :failed
|
11
|
+
raise
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Workiq
|
2
|
+
DEFAULT_EXPIRY = 60 * 30
|
3
|
+
class Storage
|
4
|
+
class << self
|
5
|
+
def store_field(jid, field)
|
6
|
+
Sidekiq.redis do |conn|
|
7
|
+
result = conn.multi do
|
8
|
+
conn.hmset jid, *(field.to_a.flatten)
|
9
|
+
conn.expire jid, Workiq::DEFAULT_EXPIRY
|
10
|
+
conn.publish "#{jid}-field-update", jid
|
11
|
+
end
|
12
|
+
result[0]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_field(jid, field)
|
17
|
+
Sidekiq.redis do |conn|
|
18
|
+
conn.hmget(jid, field)[0]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/workiq.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'workiq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "workiq"
|
8
|
+
gem.version = Workiq::VERSION
|
9
|
+
gem.authors = ["Moustafa Badawy"]
|
10
|
+
gem.email = ["moustafa@rubikal.com"]
|
11
|
+
gem.description = %q{Workiq adds Sidekiq middlewares to track a job worker status. Status values are :queued, :working, :complete, and :failed}
|
12
|
+
gem.summary = %q{Track Sidekiq job worker status}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.add_dependency 'sidekiq', '~>2.5.0'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Moustafa Badawy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sidekiq
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.5.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.5.0
|
30
|
+
description: Workiq adds Sidekiq middlewares to track a job worker status. Status
|
31
|
+
values are :queued, :working, :complete, and :failed
|
32
|
+
email:
|
33
|
+
- moustafa@rubikal.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/workiq.rb
|
44
|
+
- lib/workiq/middleware/chain.rb
|
45
|
+
- lib/workiq/middleware/client.rb
|
46
|
+
- lib/workiq/middleware/server.rb
|
47
|
+
- lib/workiq/storage.rb
|
48
|
+
- lib/workiq/version.rb
|
49
|
+
- workiq.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Track Sidekiq job worker status
|
74
|
+
test_files: []
|