Class: Job::JobFileStore

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/job.rb

Instance Method Summary (collapse)

Constructor Details

- (JobFileStore) initialize(name)

Returns a new instance of JobFileStore



27
28
29
30
31
# File 'backend/app/model/job.rb', line 27

def initialize(name)
  @job_path = File.join(AppConfig[:job_file_path], name)
  FileUtils.mkdir_p(@job_path)
  @output_path = File.join(@job_path, "output.log")
end

Instance Method Details

- (Object) close_output



60
61
62
63
64
65
# File 'backend/app/model/job.rb', line 60

def close_output
  if @output
    @output.close
    @output = nil
  end
end

- (Object) get_output_stream(offset = 0)



50
51
52
53
54
55
56
57
# File 'backend/app/model/job.rb', line 50

def get_output_stream(offset = 0)
  @output.flush if @output

  f = File.open(@output_path, "r")
  f.seek(offset, IO::SEEK_SET)

  [f, [(f.stat.size - offset), 0].max]
end

- (Object) store(file)



34
35
36
37
38
39
40
# File 'backend/app/model/job.rb', line 34

def store(file)
  target = File.join(@job_path, SecureRandom.hex)

  FileUtils.cp(file.path, target)

  target
end


68
69
70
# File 'backend/app/model/job.rb', line 68

def unlink(path)
  File.unlink(path)
end

- (Object) write_output(s)



43
44
45
46
47
# File 'backend/app/model/job.rb', line 43

def write_output(s)
  @output ||= File.open(@output_path, "a")
  @output.puts(s)
  @output.flush
end