你如何运行“Rails Runner”在heroku中?

编程入门 行业动态 更新时间:2024-10-24 04:50:14
本文介绍了你如何运行“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中?

本文发布于:2023-10-29 10:16:16,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails   Runner   heroku

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!