Pergunta

I have a Ruby on Rails 4.0 and PostgreSQL app hosted in an Ubuntu VPS. in this application I want to send email based on data in the database. for example a background job check a table content per hour and depend on content send email to user or not. I decided to do this work by Resque. how can I do that? should I do in Rails app or in an independent service? and how can I schedule this job?

Foi útil?

Solução

There are couple of more options I advise you to try to

1. Cron : One of most preferred approach for any unix developer to run a task based upon some interval . here are read more about

FYI: if you facing problem with understanding cron settings there are gem available to do the same for you its called whenever

2. Resque-Scheduler : Surely you missed one of Resque plugins that provide exactly the same feature that you need its called resque-scheduler . It too provide cron like settings for you to work on Please check the above link for more info

Hope this helps.

Outras dicas

I do not use Resque because I want a process in the Ubuntu server that in a schedule time (per hour). for example per hour check the table content and send alarm to the users by email. I make a process by Daemon and rufus-scheduler for scheduling.

Process.daemon(true)
task_test = TaskTest.new
pid = Process.fork do
  task_test.task
end

 class TaskTest
  def task
    scheduler = Rufus::Scheduler.new
    scheduler.every '1h' do
      msg = "Message"
      mailer = MailerProcess.new
      mailer.send_mail('email-address', 'password', 'to-email', 'Subject', msg)
      puts Time.now
    end
    scheduler.join
  end
end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top