你如何运行“Rails Runner”在heroku中? [英] How do you run "Rails Runner" in heroku?

查看:161
本文介绍了你如何运行“Rails Runner”在heroku中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在尝试做的事情:查找是否有人推特提供了特定的课程。如果有人确实发了推文,我想将推文保存到我的Tweet模型中,然后在相应的课程页面中显示该推文。

here is what I am trying to do: Find if anyone has tweeted about a specific course offered. If someone has indeed tweeted about it, I'd like to save that tweet to my Tweet Model and then display that tweet in the corresponding course page.

这些脚本可以在本地使用通过运行 rails runner get_tweets.rb ,但是在Heroku上,似乎脚本被执行但不写入数据库。在heroku中,我正在运行 heroku run rails runner get_tweets.rb (使用Cedar堆栈)。

The scripts works locally by running rails runner get_tweets.rb but on Heroku it seems that the script gets executed but doesn't write to the database. In heroku I am running heroku run rails runner get_tweets.rb (using the Cedar stack).

def get_course_tweets
  @courses = Course.all
  @courses.each do |course|
    url = course.url
    tweets = Twitter.search(url, {:rpp => 100, :recent => true, :show_user => true})
    tweets.each do |tweet_info|
      unless Tweet.find_by_tweet_id(tweet_info.id).present?
        tweet = Tweet.new
        tweet.course_id = course.id
        tweet.tweet_id = tweet_info.id
        tweet.tweet_text = tweet_info.text
        tweet.from_user = tweet_info.from_user
        begin
          tweet.save!
        rescue => error
          puts error
        end
      end
    end
  end
end

编辑:

我从救援中获得的当前错误如下:

The current error I get from rescue is the following:

PG::Error: ERROR:  value "186306985577299969" is out of range for type integer : INSERT INTO "tweets" ("book_id", "course_id", "created_at", "from_user", "tutorial_id",     "tweet_already_exists", "tweet_id", "tweet_posted_to_reviews", "tweet_text", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"


推荐答案


$ b

As can be seen from your error


值186306985577299969超出整数类型的范围

value "186306985577299969" is out of range for type integer

您需要使用不同的数据类型(对于 tweet_id ,我相信),大概是 BIG INT ,范围从-9223372036854775808到9223372036854775807。

you need to use a different datatype (for tweet_id, I believe), presumably a BIGINT, which ranges from -9223372036854775808 to 9223372036854775807.

要在Rails中这样做,您可以传递 :limit => 8 在您的 up 迁移中:

To do so in Rails you can pass :limit => 8 in your up migration:

change_column :tweets, :tweet_id, :integer, :limit => 8

请注意,您应始终做某种日志记录或报告你 rescue ,否则像这样的错误变得非常难以追踪,因为它们悄无声息地被绕过。

Note that you should always do some sort of logging or reporting when you rescue, or else bugs like this become very difficult to track down because they silently get bypassed.

这篇关于你如何运行“Rails Runner”在heroku中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆