Class: Xxeo::Job
- Inherits:
-
Object
- Object
- Xxeo::Job
- Defined in:
- lib/job.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#callback_read_logs ⇒ Object
The @fq locks and then does a callback here.
-
#callback_status_mesg ⇒ Object
The @fq locks and then does a callback here.
- #data ⇒ Object
- #disown ⇒ Object
- #is_file? ⇒ Boolean
- #log(msg) ⇒ Object
- #mark_done ⇒ Object
- #mark_error ⇒ Object
- #name ⇒ Object
- #original_pathname ⇒ Object
- #own? ⇒ Boolean
- #owning_pid ⇒ Object
- #pull ⇒ Object
- #read_log ⇒ Object
- #read_meta ⇒ Object
- #reinsert ⇒ Object
- #set_as_active ⇒ Object
- #set_status(path, status) ⇒ Object
-
#status ⇒ Object
TODO: this could be stale.
- #status_all ⇒ Object
-
#status_mesg ⇒ Object
TODO: this could be stale.
- #status_mesg=(msg) ⇒ Object
Class Method Details
.create(queue, name, path, status) ⇒ Object
11 12 13 14 15 |
# File 'lib/job.rb', line 11 def Job.create(queue, name, path, status) raise unless queue.class == Xxeo::FileQ Job.new(queue, name, path, status) end |
Instance Method Details
#callback_read_logs ⇒ Object
The @fq locks and then does a callback here
137 138 139 140 141 142 143 144 |
# File 'lib/job.rb', line 137 def callback_read_logs data = '' File.open(@path + '/log', "r") do |f| data = f.read end return data end |
#callback_status_mesg ⇒ Object
The @fq locks and then does a callback here
102 103 104 105 106 107 108 109 |
# File 'lib/job.rb', line 102 def callback_status_mesg data = '' File.open(@path + '/status', "r") do |f| data = f.read end return data end |
#data ⇒ Object
21 22 23 24 25 26 |
# File 'lib/job.rb', line 21 def data raise WrongStatus.new('cannot disown a non-owned job') unless @own data = nil File.open(@path + '/data') { |f| data = f.read } return data end |
#disown ⇒ Object
53 54 55 56 57 58 |
# File 'lib/job.rb', line 53 def disown raise WrongStatus.new('cannot disown a non-owned job') unless @own @own = false File.unlink(@path + '/pid') @owning_pid = nil end |
#is_file? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/job.rb', line 32 def is_file? = raise unless return [:XX_type] == 'file' end |
#log(msg) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/job.rb', line 121 def log(msg) raise WrongStatus.new('cannot log on non-owned job') unless @own File.open(@path + '/log', "a") do |f| log_msg = Time.now.to_s + " == " + msg + "\n" f.write(log_msg) @logs << log_msg end end |
#mark_done ⇒ Object
146 147 148 149 150 |
# File 'lib/job.rb', line 146 def mark_done raise WrongStatus.new('cannot mark job as done on non-owned job') unless @own status_mesg = "finishing" @fq.mark_job_done(self) end |
#mark_error ⇒ Object
152 153 154 155 156 |
# File 'lib/job.rb', line 152 def mark_error raise WrongStatus.new('cannot mark job as error on non-owned job') unless @own status_mesg = "finishing" @fq.mark_job_error(self) end |
#name ⇒ Object
17 18 19 |
# File 'lib/job.rb', line 17 def name return @name end |
#original_pathname ⇒ Object
38 39 40 41 42 43 |
# File 'lib/job.rb', line 38 def original_pathname = raise unless return [:XX_original_file_name] if [:XX_type] == 'file' return nil end |
#own? ⇒ Boolean
49 50 51 |
# File 'lib/job.rb', line 49 def own? @own end |
#owning_pid ⇒ Object
28 29 30 |
# File 'lib/job.rb', line 28 def owning_pid @owning_pid end |
#pull ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/job.rb', line 65 def pull return self if @own # This is kinda wonky, obviously # since the @fq already called set_as_active on an object if @fq.pull_job(@name) @own = true @path = @fq.run_que_path + @name @status = ST_RUN @owning_pid = $$ return self end return nil end |
#read_log ⇒ Object
131 132 133 134 |
# File 'lib/job.rb', line 131 def read_log return @logs.join('') if @own return @fq.status_logs_for_job(@name) end |
#read_meta ⇒ Object
45 46 47 |
# File 'lib/job.rb', line 45 def return @fq.(@name) end |
#reinsert ⇒ Object
158 159 160 161 162 163 |
# File 'lib/job.rb', line 158 def reinsert raise WrongStatus.new('cannot reinsert on non-owned job') unless @own status_mesg = "reinserting" log("reinserting job") @fq.reinsert_job(self) end |
#set_as_active ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/job.rb', line 80 def set_as_active @own = true # Record @path = @fq.run_que_path + @name @status = ST_RUN File.open(@path + '/pid', "w") { |f| f.write("#{$$}\n") } @owning_pid = $$ end |
#set_status(path, status) ⇒ Object
60 61 62 63 |
# File 'lib/job.rb', line 60 def set_status(path, status) @path = path @status = status end |
#status ⇒ Object
TODO: this could be stale
90 91 92 93 |
# File 'lib/job.rb', line 90 def status return @status if @own return @fq.status(@name) end |
#status_all ⇒ Object
117 118 119 |
# File 'lib/job.rb', line 117 def status_all return [@status, @owning_pid, status_mesg] end |
#status_mesg ⇒ Object
TODO: this could be stale
96 97 98 99 |
# File 'lib/job.rb', line 96 def status_mesg return @status_mesg if @own return @fq.status_mesg_for_job(@name) end |
#status_mesg=(msg) ⇒ Object
111 112 113 114 115 |
# File 'lib/job.rb', line 111 def status_mesg=(msg) raise WrongStatus.new('cannot set status mesg on non-owned job') unless @own @status_mesg = msg File.open(@path + '/status', "w") { |f| f.write(msg) } end |