Method: Exedb#update
- Defined in:
- lib/exedb.rb
#update ⇒ Object
Force command execution. If another instance with the same command is in progress, no new execution will be started
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/exedb.rb', line 66 def update @content='' # create file if needed unless File.file?(@path) File.open(@path,File::RDWR|File::CREAT,0644){|f|} end File.open(@path, "r+:UTF-8") { |file| if file.flock(File::LOCK_EX|File::LOCK_NB) begin IO.popen(@update_method){|pipe| line=pipe.gets while line line=@transform.call(line) if @transform if line file.puts line file.flush @content = @content+line end line=pipe.gets end } @code=$?.exitstatus rescue @content='' @code=-1 end if @alltransform @content=@alltransform.call(@content,@code) file.seek(0,IO::SEEK_SET) file.write @content file.truncate(@content.size) file.flush end File.open("#{@path}.code",File::RDWR|File::CREAT, 0644){|code_file| code_file.puts @code } file.flock(File::LOCK_UN) else read_cache end @update_time=Time.now } #!!!warn "UPDATED!'" @content end |