Rails Rake 任务中如何关闭 PostgreSQL 事务?

nine · April 21, 2016 · Last by nine replied at April 21, 2016 · 2178 hits

目前服务器上运行了 Rake 任务来持续导入数据,使用 God 管理进程。 但是某些异常会导致数据回滚,最多一次回滚了 8 天,超级吓人。 是否有方法仅在 rake 任务中关闭 PostgreSQL 的事务?

1 Floor has deleted

#1 楼 @jjfujj 介个。。应该和 shell 命令没有关系,不是要关闭事务,而是在导入的那个进程中不启用事务

查到写 rspec 中可以 通过

RSpec.configure do |config|
  config.use_transactional_fixtures = false
end

关闭事务。 目前 rake 方法还没找到

3 Floor has deleted

#3 楼 @jjfujj

redis = Rredis.instance
while json = redis.rpop('xxx_list')
  data = JSON.parse json
  record = PeopleRecord.new
  record.xxx = data.xxx
  record.save
  # end
  p record.stadct_id
end
You need to Sign in before reply, if you don't have an account, please Sign up first.