#! /usr/bin/env ruby ### ### setup rails env/libs ### rails_root = File.dirname __FILE__ require File.join(rails_root, 'config','boot') require File.join(rails_root, 'config','environment') require 'yaml' require '../lib/rq' ### ### note that config is just a hash but i'm parsing this yaml because i pasted ### it in from a config file, normally you'd simply use a nested hash as the ### argument ### this_file = File.expand_path __FILE__ yml = <<-yml cmd: env && echo 42 mail: To: ara.t.howard@eparklabs.com From: ara.t.howard@eparklabs.com Subject: testing 1-2-3 Cc: ara.t.howard@gmail.com attach: #{ this_file } yml ### put this in theconfig if you want to use smtp =begin smtp: account : ara.t.howard@eparklabs.com tls : true port : 25 server : secure.eparklabs.com domain : eparklabs.com authtype : :plain password : :password =end config = YAML.load yml ### ### the templated message will have access to lots of info about the job run ### template = <<-template hi <%= [ To, Cc ].join ',' %> this is about <%= subject %> the command ran was <%= command.inspect %> the exitstatus was <%= exitstatus.inspect %> the stdin was <%= stdin.inspect %> the stdout was <%= stdout.inspect %> the stderr was <%= stderr.inspect %> the time now <%= require 'time'; Time.now.iso8601(2) %> this message was generated from a command run under rq. neat huh? template ### ### this is the __entire__ api for summitting a job to run and wrapping the ### completion the sending of a message. the job submitted can have stdin and ### a bunch of other stuff specified, however, this is a simple example ### job = Rails.q.mailrun config, template, :priority => 42 jid = job['jid'] ### ### this would be running under cron and/or daemon, or otherwise in the ### background, but we run it here by hand ### system "rq ./q feed --loops=1" puts '...' puts system "cat ./q/stdout/#{ jid }" puts '...' puts system "head ./q/data/#{ jid }/smtp" puts '...' puts system "head ./q/data/#{ jid }/mail" puts '...' puts