Class: Process::Naf::LogArchiver

Inherits:
Application
  • Object
show all
Defined in:
app/models/process/naf/log_archiver.rb

Constant Summary collapse

NAF_JOBS_LOG_PATH =
"#{::Naf::PREFIX_PATH}/#{::Naf.schema_name}/jobs/"
NAF_RUNNERS_LOG_PATH =
"#{::Naf::PREFIX_PATH}/#{::Naf.schema_name}/runners/"
DATE_REGEX =
/\d{8}_\d{6}/
LOG_RETENTION =
1

Instance Method Summary collapse

Instance Method Details

#workObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/process/naf/log_archiver.rb', line 11

def work
	# Use AWS credentials to access S3
s3 = AWS::S3.new(access_key_id: AWS_ID,
                    secret_access_key: AWS_KEY,
                    ssl_verify_peer: false)

# Each project will have a specific bucket
bucket = s3.buckets[NAF_BUCKET]
   files = log_files

   logger.info 'Starting to save files to s3...'
   files.each do |file|
     # Write file if not existent
     object = bucket.objects["#{NAF_LOG_PATH}/#{creation_time}" + file[12..-1]]
     if !object.exists?
       # Write file to S3
       result = object.write(File.open(file).read)
       logger.info "File #{file} saved to S3"
     end
   end

   logger.info 'Starting to archive files...'
   archive_old_files(files)
end