在Heroku免费应用程序中,dynos似乎保持闲置 - 我的应用程序的流量非常低,但在我的情况下,我的用户还必须等待20多秒才能启动新的dyno.
坦率地说,有了这种等待,很多人会在第一页显示之前离开.
所以,我有一个问题:当我的流量是每天一位数时,我应该每月支付36美元来为每个用户节省一个令人尴尬的长20秒.
有没有解决的办法??
在./config/initializers我创建了一个名为的文件中task_scheduler.rb,它包含以下代码:
require 'rufus-scheduler'
require 'mechanize'
scheduler = Rufus::Scheduler.new
scheduler.every("1h") do
puts "Starting Rufus Scheduler - Task 1 - Checking exampleShop for new orders"
a = Mechanize.new
a.get('http://exampleshop.nl/admin/') do |page|
# Select the login form
login_form = page.forms.first
# Insert the username and password
login_form.username = 'username'
login_form.password = 'password'
# Submit the login information
dashboard_page = a.submit(login_form, login_form.buttons.first)
# Check if the login was successfull
puts check_1 = dashboard_page.title == 'Dashboard' ? "CHECK 1 DASHBOARD SUCCESS" …Run Code Online (Sandbox Code Playgroud)