Module: QuickUtils::Job::ClassMethods

Defined in:
lib/quick_utils/job.rb

Instance Method Summary collapse

Instance Method Details

#job_mongo_keys!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/quick_utils/job.rb', line 6

def job_mongo_keys!
	key :jt,  Integer                   # job type
	key :pr,  Integer, :default => 0    # priority
	key :ip,  Boolean, :default => false  # in process
	key :opt, Hash

	attr_alias :job_type, :jt
	attr_alias :priority, :pr
	attr_alias :in_progress, :ip
	cattr_accessor :job_types
	self.job_types = {}
			
	# NAMED SCOPES
	scope :with_job_type, lambda { |job_type|
		where(:jt => job_type)
	}
	scope :processing, lambda {
		where(:ip => true)
	}
	scope :unprocessed, lambda {
		where(:ip => false)
	}
	scope :by_priority, lambda {
		sort(:pr.asc)
	}

	timestamps!
end

#ready_for(jt) ⇒ Object



35
36
37
# File 'lib/quick_utils/job.rb', line 35

def ready_for(jt)
	self::with_job_type(self::job_types[jt]).unprocessed
end