S
Simon Strandgaard
Hi list,
Howto capture stdout + stderr from jobs invoked with rake?
I run rake from cron. I have a
def log(msg)
=09str =3D Time.now.to_s + ": " + msg + "\n"
=09file =3D $settings['logfile']
=09File.open(file, 'a+') {|f| f.write str }
end
it only tells where it went wrong, but not what went wrong.
any ideas how to do better logging with the following code?
--
Simon Strandgaard
desc "creates a hotcopy backup of the repository."
task :backup =3D> [:clean] do
ok =3D true
log('create hotcopy')
tmpdir =3D $settings['backup_tmpdir_name']
repo_path =3D $settings['backup_repository_path']
create_hotcopy(repo_path, tmpdir)
log('compressing')
zipfile =3D $settings['backup_zipfile']
compress_dir(tmpdir, zipfile)
log('encrypting')
passphrase =3D $settings['passphrase']
cryptfile =3D $settings['backup_cryptfile']
encrypt_file(zipfile, cryptfile, passphrase)
log('splitting into chunks')
# split file into small chunks (that can go with the mail)
prefix =3D $settings['backup_chunk_prefix']
size =3D $settings['backup_chunk_size']
split_file(cryptfile, size, prefix)
# send a mail with each chunk attached
rev =3D youngest_revision(tmpdir)
time =3D Time.now.strftime('%Y%m%d')
subject =3D "hotcopy#{time}_rev#{rev}"
reciever =3D $settings['backup_recievers']
mime =3D 'application/octet-stream'
chunks =3D Dir.glob(prefix + '*').sort
log("revision #{rev}, consists of #{chunks.size} chunks.")
chunks.each_with_index do |filename, index|
log("sending chunk##{index+1}.")
bodytext =3D "this is chunk##{index+1} out of #{chunks.size} in total."
attachments =3D [[filename, mime]]
begin
send_mail(reciever, subject, bodytext, attachments)
=09=09rescue =3D> e
=09=09=09log("ERROR: failed sending, #{e.inspect}")
=09=09=09ok =3D false
=09=09end
end
msg =3D ok ? "OK" : "with error!"
log("backup completed #{msg}\n\n")
end
Howto capture stdout + stderr from jobs invoked with rake?
I run rake from cron. I have a
def log(msg)
=09str =3D Time.now.to_s + ": " + msg + "\n"
=09file =3D $settings['logfile']
=09File.open(file, 'a+') {|f| f.write str }
end
it only tells where it went wrong, but not what went wrong.
any ideas how to do better logging with the following code?
--
Simon Strandgaard
desc "creates a hotcopy backup of the repository."
task :backup =3D> [:clean] do
ok =3D true
log('create hotcopy')
tmpdir =3D $settings['backup_tmpdir_name']
repo_path =3D $settings['backup_repository_path']
create_hotcopy(repo_path, tmpdir)
log('compressing')
zipfile =3D $settings['backup_zipfile']
compress_dir(tmpdir, zipfile)
log('encrypting')
passphrase =3D $settings['passphrase']
cryptfile =3D $settings['backup_cryptfile']
encrypt_file(zipfile, cryptfile, passphrase)
log('splitting into chunks')
# split file into small chunks (that can go with the mail)
prefix =3D $settings['backup_chunk_prefix']
size =3D $settings['backup_chunk_size']
split_file(cryptfile, size, prefix)
# send a mail with each chunk attached
rev =3D youngest_revision(tmpdir)
time =3D Time.now.strftime('%Y%m%d')
subject =3D "hotcopy#{time}_rev#{rev}"
reciever =3D $settings['backup_recievers']
mime =3D 'application/octet-stream'
chunks =3D Dir.glob(prefix + '*').sort
log("revision #{rev}, consists of #{chunks.size} chunks.")
chunks.each_with_index do |filename, index|
log("sending chunk##{index+1}.")
bodytext =3D "this is chunk##{index+1} out of #{chunks.size} in total."
attachments =3D [[filename, mime]]
begin
send_mail(reciever, subject, bodytext, attachments)
=09=09rescue =3D> e
=09=09=09log("ERROR: failed sending, #{e.inspect}")
=09=09=09ok =3D false
=09=09end
end
msg =3D ok ? "OK" : "with error!"
log("backup completed #{msg}\n\n")
end