ost-job 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf157669a9fa68fba51edff012ef23c333a51fbf
4
+ data.tar.gz: cc9484c6ae96085f9bda35d8de8bd9cf61bb34bd
5
+ SHA512:
6
+ metadata.gz: 0f2c57418b5950dc607ff83a9378a94d3fbfcb574952d397a9a8eee003fd4d3ae46eec2b8cd87a49213191f88724cccbadbeab7e7d495a9e963dae4dc86ff1d9
7
+ data.tar.gz: e2a55ee73a1b9a6636a4db771f296b93da7d40203e22bc7845a6598606fcde1662db98e8088f9b1e2452fa91707090ea377b0da45986283143c426fb668e2c9c
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Brendon Murphy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ test:
2
+ cutest test/*.rb
3
+
4
+ .PHONY: test
@@ -0,0 +1,53 @@
1
+ Ost::Job
2
+ ========
3
+
4
+ Job base classes for [Ost](https://github.com/soveran/ost) and
5
+ [ost-bin](https://github.com/djanowski/ost-bin).
6
+
7
+ Description
8
+ -----------
9
+
10
+ Ost provides simple, lightweight background job functionality. By
11
+ default, it assumes you are passing very primative ids like a numeric
12
+ user id to the queue.
13
+
14
+ `Ost::Job` and `Ost::JsonJob` provide a super thin interface to a job
15
+ class that plays nice with `ost-bin`.
16
+
17
+ Installation
18
+ ------------
19
+
20
+ $ gem install ost-job
21
+
22
+ Usage
23
+ -----
24
+
25
+ Setup your `Ostfile` as specified by ost-bin.
26
+
27
+ Declare a job class with a `#perform` instance method.
28
+
29
+ For a regular job that is passed a single id or string:
30
+
31
+ ```ruby
32
+ class Plain < Ost::Job
33
+ def perform(user_id)
34
+ user = User.find(id)
35
+ # do something with user
36
+ end
37
+ end
38
+ ```
39
+
40
+ If you want to pass richer data to your job, inherit `Ost::JsonJob`
41
+
42
+ ```ruby
43
+ # Enqueue the job
44
+ Ost[:Mailer] << {user_id: 42, subject: 'Hello', body: 'World'}.to_json
45
+
46
+ # Declare your Job Class
47
+ class Mailer < Ost::JsonJob
48
+ def perform(data)
49
+ user = User.find(data['id'])
50
+ Mail.deliver(user: user, subject: data['subject'], body: data['body'])
51
+ end
52
+ end
53
+ ```
@@ -0,0 +1,19 @@
1
+ require "json"
2
+
3
+ module Ost
4
+ class Job
5
+ def call(data)
6
+ perform(deserialize(data))
7
+ end
8
+
9
+ def deserialize(data)
10
+ data
11
+ end
12
+ end
13
+
14
+ class JsonJob < Job
15
+ def deserialize(data)
16
+ JSON[data]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ost-job"
3
+ s.version = "0.0.1"
4
+ s.summary = "Job base classes for Ost"
5
+ s.description = s.summary
6
+ s.authors = ["Brendon Murphy"]
7
+ s.email = ["xternal1+github@gmail.com"]
8
+ s.homepage = "http://github.com/bemurphy/ost-job"
9
+ s.license = "MIT"
10
+
11
+ s.files = Dir[
12
+ "LICENSE",
13
+ "README.md",
14
+ "Makefile",
15
+ "lib/**/*.rb",
16
+ "*.gemspec",
17
+ "test/**/*.rb"
18
+ ]
19
+
20
+ s.add_development_dependency "cutest", "~> 1.2"
21
+ end
@@ -0,0 +1,29 @@
1
+ require "cutest"
2
+ require_relative "../lib/ost/job"
3
+
4
+ class PlainJob < Ost::Job
5
+ def perform(data)
6
+ $plain_data ||= []
7
+ $plain_data << data
8
+ end
9
+ end
10
+
11
+ test "deserializing the data for a plain job" do
12
+ PlainJob.new.call(1)
13
+ PlainJob.new.call(22)
14
+ PlainJob.new.call(333)
15
+ assert_equal [1, 22, 333], $plain_data
16
+ end
17
+
18
+ class JsonJob < Ost::JsonJob
19
+ def perform(data)
20
+ $deserialized_data ||= []
21
+ $deserialized_data << data
22
+ end
23
+ end
24
+
25
+ test "deserializing the data for a json based job" do
26
+ JsonJob.new.call(JSON.dump({foo: 'bar', job: 1}))
27
+ JsonJob.new.call(JSON.dump({fizz: 'buzz', job: 2}))
28
+ assert_equal [{"foo" => "bar", "job" => 1}, {"fizz" => "buzz", "job" => 2}], $deserialized_data
29
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ost-job
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brendon Murphy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ description: Job base classes for Ost
28
+ email:
29
+ - xternal1+github@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - Makefile
36
+ - README.md
37
+ - lib/ost/job.rb
38
+ - ost-job.gemspec
39
+ - test/ost_job_test.rb
40
+ homepage: http://github.com/bemurphy/ost-job
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Job base classes for Ost
64
+ test_files: []