2

我正在使用赛璐珞在后台执行一些工作,一些工作正在使用数据库,为此我在单元格(演员)中使用以下代码:

ActiveRecord::Base.connection_pool.with_connection do
  User.find(123)
end

在某些情况下,我有一些服务正在排队数据库,但其中包含一些其他逻辑。我可以将它们发送到...with_connection或者我需要将电话包裹在里面吗?有没有更好的方法来做这一切?

ActiveRecord::Base.connection_pool.with_connection do
  SomeService.new(params).get_records
end

class SomeService
  def initialise(param)
    @params = params
  end

  def get_records
     some_logic
     ServicePersistenceModel.where(id: prams.id)
  end
end
4

0 回答 0