Class: Job::JobFileStore

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

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ JobFileStore

Returns a new instance of JobFileStore.



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

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

Instance Method Details

#close_outputObject



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

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

#get_output_stream(offset = 0) ⇒ Object



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

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

#store(file) ⇒ Object



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

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

  FileUtils.cp(file.path, target)

  File.join(@job_dir, filename)
end


70
71
72
# File 'backend/app/model/job.rb', line 70

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

#write_output(s) ⇒ Object



45
46
47
48
49
# File 'backend/app/model/job.rb', line 45

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