1

次のコードがあります。その仕事は、ブラウザを介して (Sinatra を使用して) 提供されたデータに基づいて電子メールを送信することです。20 秒後に指定されたアドレスに電子メールを送信します。プログラムを実行すると、時間を待たずにすぐにメールが送信されます。誰でもこの問題で私を助けてくれますか?

require 'rubygems'
require 'sinatra'
require 'pony'
require 'resque'
require 'resque_scheduler'
require 'active_support/time'

Resque.redis = 'localhost:6379'
Resque::Scheduler.dynamic = true

def sendMail

Pony.mail({
  :to => 'eldurotaduro@gmail.com',
  :via => :smtp,
  :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => 'EMAIL',
    :password             => 'PASSWD',
    :authentication       => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain               => "localhost.localdomain" # the HELO domain provided by the            client to the server
  },
   :body => 'roar'
})

end


class Roar
    def self.queue; :app; end
end

class ChildJob 

@message
@email

def setMess(mes)
    @message = mes
end

def setMail(mail)
    @email = mail
end


def self.queue; :app; sendMail; end

def self.perform
  Pony.mail({
  :to => 'eldurotaduro@gmail.com',
  :via => :smtp,
  :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => 'EMAILHERE@gmail.com',
    :password             => 'PASSWD',
    :authentication       => :plain, # :plain, :login, :cram_md5, no auth by default
    :domain               => "localhost.localdomain" # the HELO domain provided by the client to the server
  },
   :body => 'HAHAH'
})
end

end



get '/:email/:message/:time' do

email = params[:email]
message = params[:message]
time = params[:time]
time = time.to_i

Resque.enqueue_in(20.seconds, ChildJob)

end
4

1 に答える 1

0

それがデフォルトのキューを設定するものであるため、:appシンボルをそのままにしておきます(この StackOverflow answerを参照してください)。スケジュールが満たされたときに実行したいことなので、 をメソッドに入れます。例えばself.queuesendMailself.perform

def self.queue
  :app
end

def self.perform
  sendMail
end
于 2013-03-27T04:17:15.943 に答える