开发者

Send ActionMailer from external ruby file?

开发者 https://www.devze.com 2023-03-28 19:26 出处:网络
i want to make a cronjob which execute a specific ruby file in the script dir开发者_Python百科ectory of my rails app. how can i achieve, that i can execute an actionmailer to use deliver? how do i get

i want to make a cronjob which execute a specific ruby file in the script dir开发者_Python百科ectory of my rails app. how can i achieve, that i can execute an actionmailer to use deliver? how do i get this mailer into this ruby file?

thanks!


Skipping the part about creating a task in crontab, here is what you can do:

  1. Create a rake task, in lib/tasks, which sends that email and invoke the rake task from your cron job. I have done this and this works, pretty well for me.
  2. Load the Rails environment explicitly in your ruby script. I do this in some daemons. You can do something like this :

    require File.dirname(__FILE__) + "/../config/application"
    Rails.application.require_environment!
    
  3. Use the rails runner. rails runner -h will give you the necessary information

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号