29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rq/rails.rb', line 29
def qextension
Module.new do
def rqmailer config, template = nil, submission = {}
config = YAML.load config if String === config
config = config.inject({}){|h,kv| k, v = kv; h.update k.to_s => v}
submission = submission.inject({}){|h,kv| k, v = kv; h.update k.to_s => v}
command = (config["command"] || config["cmd"]) or raise "no command in <#{ config.inspect }>!"
mconfig = config["mail"] || config
attachements = [ mconfig["attach"] ].flatten.compact
tag = "rqmailer"
command = "rqmailer ### #{ command }"
submission["tag"] ||= tag
submission["command"] = command
tmpdir = File.join RAILS_ROOT, 'tmp', Process.pid.to_s, '.rqmailer.d'
FileUtils.mkdir_p tmpdir
begin
open(File.join(tmpdir, 'config'), 'w') do |fd|
fd.write config.to_yaml
end
if template
open(File.join(tmpdir, 'template'), 'w') do |fd|
fd.write template
end
end
d = File.join(tmpdir, "attachements")
FileUtils.mkdir_p d
attachements.each do |attachment|
FileUtils.cp attachment, d
end
submission["data"] = tmpdir
job = nil
submit(submission){|job|}
job
ensure
FileUtils.rm_rf tmpdir
end
end
alias_method "mailrun", "rqmailer"
end
end
|