Class: Patriot::JobStore::Job
- Inherits:
-
Object
- Object
- Patriot::JobStore::Job
- Defined in:
- lib/patriot/job_store/job.rb
Overview
a record stored in jobstore
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#job_id ⇒ Object
Returns the value of attribute job_id.
-
#update_id ⇒ Object
Returns the value of attribute update_id.
Instance Method Summary collapse
-
#[](k) ⇒ Object
get an attribute to this job.
-
#[]=(k, v) ⇒ Object
set an attribute to this job.
-
#_from_stdobj(obj, config) ⇒ Object
convert corresponding objects in the given argument into Command instances.
-
#delete(k) ⇒ Object
delete an attribute.
-
#filter_attributes(attrs) ⇒ Hash
A set of attribute name value pairs for specified attributes.
-
#initialize(job_id) ⇒ Job
constructor
A new instance of Job.
-
#read_command(command) ⇒ Object
read the content of command.
-
#to_command(config) ⇒ Patriot::Command::Base
An executable for this job.
Constructor Details
#initialize(job_id) ⇒ Job
Returns a new instance of Job.
9 10 11 12 13 14 15 |
# File 'lib/patriot/job_store/job.rb', line 9 def initialize(job_id) @job_id = job_id @attributes = { Patriot::Command::PRIORITY_ATTR => Patriot::JobStore::DEFAULT_PRIORITY, Patriot::Command::STATE_ATTR => Patriot::JobStore::JobState::INIT } end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/patriot/job_store/job.rb', line 6 def attributes @attributes end |
#job_id ⇒ Object
Returns the value of attribute job_id.
6 7 8 |
# File 'lib/patriot/job_store/job.rb', line 6 def job_id @job_id end |
#update_id ⇒ Object
Returns the value of attribute update_id.
6 7 8 |
# File 'lib/patriot/job_store/job.rb', line 6 def update_id @update_id end |
Instance Method Details
#[](k) ⇒ Object
get an attribute to this job
28 29 30 31 |
# File 'lib/patriot/job_store/job.rb', line 28 def [](k) raise "key #{k} should be symbol but #{k.class}" unless k.is_a?(Symbol) return @attributes[k] end |
#[]=(k, v) ⇒ Object
set an attribute to this job
20 21 22 23 |
# File 'lib/patriot/job_store/job.rb', line 20 def []=(k,v) raise "key #{k} should be symbol but #{k.class}" unless k.is_a?(Symbol) @attributes[k] = v end |
#_from_stdobj(obj, config) ⇒ Object
convert corresponding objects in the given argument into Command instances.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/patriot/job_store/job.rb', line 94 def _from_stdobj(obj, config) if obj.is_a?(Hash) if obj.has_key?(Patriot::Command::COMMAND_CLASS_KEY) cmd_cls = obj.delete(Patriot::Command::COMMAND_CLASS_KEY) cmd_cls = cmd_cls.split('.').inject(Object){|c,name| c.const_get(name)} cmd = cmd_cls.new(config) obj.each do |k,v| cmd.instance_variable_set("@#{k}".to_sym, _from_stdobj(v, config)) end return cmd elsif obj.has_key?(Patriot::Command::PostProcessor::POST_PROCESSOR_CLASS_KEY) cmd_cls = obj.delete(Patriot::Command::PostProcessor::POST_PROCESSOR_CLASS_KEY) cmd_cls = cmd_cls.split('.').inject(Object){|c,name| c.const_get(name)} return cmd_cls.new(obj) else hash = {} obj.each{|k,v| hash[k.to_s] = _from_stdobj(v, config)} return hash end elsif obj.is_a?(Array) return obj.map{|e| _from_stdobj(e, config)} else return obj end end |
#delete(k) ⇒ Object
delete an attribute
36 37 38 39 |
# File 'lib/patriot/job_store/job.rb', line 36 def delete(k) raise "key #{k} should be symbol but #{k.class}" unless k.is_a?(Symbol) return @attributes.delete(k) end |
#filter_attributes(attrs) ⇒ Hash
Returns a set of attribute name value pairs for specified attributes.
122 123 124 125 126 |
# File 'lib/patriot/job_store/job.rb', line 122 def filter_attributes(attrs) filtered = {} attrs.each{|a| filtered[a] = self[a]} return filtered end |
#read_command(command) ⇒ Object
read the content of command
43 44 45 46 47 48 49 |
# File 'lib/patriot/job_store/job.rb', line 43 def read_command(command) Patriot::Command::COMMON_ATTRIBUTES.each do |attr| value = command.instance_variable_get("@#{attr}".to_sym) self[attr] = _to_stdobj(value) unless value.nil? end _to_stdobj(command).each{|k,v| self[k] = v} end |
#to_command(config) ⇒ Patriot::Command::Base
Returns an executable for this job.
84 85 86 87 |
# File 'lib/patriot/job_store/job.rb', line 84 def to_command(config) raise "configuration is not set" if config.nil? return _from_stdobj(self.attributes, config) end |