quick_utils 0.0.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/quick_utils.rb CHANGED
@@ -3,6 +3,7 @@ require "quick_utils/thread_runner"
3
3
  require "quick_utils/rails_daemon"
4
4
  require "quick_utils/rake_daemon"
5
5
  require "quick_utils/watcher"
6
+ require "quick_utils/job"
6
7
 
7
8
  module QuickUtils
8
9
  # Your code goes here...
@@ -0,0 +1,52 @@
1
+ module QuickUtils
2
+ module Job
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def job_mongo_keys!
7
+ key :jt, Integer # job type
8
+ key :pr, Integer, :default => 0 # priority
9
+ key :ip, Boolean, :default => false # in process
10
+ key :opt, Hash
11
+
12
+ attr_alias :job_type, :jt
13
+ attr_alias :priority, :pr
14
+ attr_alias :in_progress, :ip
15
+ cattr_accessor :job_types
16
+ self.job_types = {}
17
+
18
+ # NAMED SCOPES
19
+ scope :with_job_type, lambda { |job_type|
20
+ where(:jt => job_type)
21
+ }
22
+ scope :processing, lambda {
23
+ where(:ip => true)
24
+ }
25
+ scope :unprocessed, lambda {
26
+ where(:ip => false)
27
+ }
28
+ scope :by_priority, lambda {
29
+ sort(:pr.asc)
30
+ }
31
+
32
+ timestamps!
33
+ end
34
+
35
+ def ready_for(jt)
36
+ self::with_job_type(self::job_types[jt]).unprocessed
37
+ end
38
+ end
39
+
40
+ module InstanceMethods
41
+ def is_processing?
42
+ self.ip == true
43
+ end
44
+
45
+ def processing!
46
+ self.ip = true
47
+ self.save
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module QuickUtils
2
- VERSION = "0.0.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 0
9
- - 4
10
- version: 0.0.4
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alan Graham
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-22 00:00:00 Z
18
+ date: 2012-07-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: daemons
@@ -45,6 +45,7 @@ files:
45
45
  - Gemfile
46
46
  - Rakefile
47
47
  - lib/quick_utils.rb
48
+ - lib/quick_utils/job.rb
48
49
  - lib/quick_utils/rails_daemon.rb
49
50
  - lib/quick_utils/rake_daemon.rb
50
51
  - lib/quick_utils/thread_runner.rb