在rails activerecord中保存多个对象

时间:2017-02-04 23:57:51

标签: ruby ruby-on-rails-4 activerecord

我有一个Rails + Heroku scheduler.rake的重复工作。

问题是当条目太多时,它不会成功保存它们。

如何更改此代码以使所有保存完成且没有错误?

这种方法不需要快速完成,因为它可以在早上的固定时间内工作,所以我可以一点一点地保存它,但有一些延迟。

(我每次1x,25美元/月使用Heroku网络和工作人员)

谢谢!

*使用错误日志2017/02/08编辑

class RecurringEntryJob < ActiveJob::Base
  queue_as :default

  def perform(*args)

    # Get active recurring entries
    recurring_entries = Recurring.where(deleted: false)

    Rails.logger.info "Recurring_Entry_Called"

    for recurring_entry in recurring_entries

        Rails.logger.info "“Recurring_Entry Processing for - #{recurring_entry[:id]}"

        # Get the current time with saved timezone
        timezone        = recurring_entry["timezone"]
        current_time    = Time.now.in_time_zone(timezone)

        setDate = recurring_entry["date"]

        # Check if daily is set
        if setDate  == 0 || 

           # Checkc if weekday matches
           setDate  == current_time.wday + 1 ||

           # Check if monthly date or end of month match
           setDate  == current_time.day + 7 || current_time.tomorrow.day == 1 && setDate == 36

           Rails.logger.info "Recurring_Entry Day of the week check passed for - #{recurring_entry[:id]}"

            # Save an entry at AM4:00
            if current_time.hour == 4

                Rails.logger.info "Recurring_Entry All cheks passed for - #{recurring_entry[:id]} - creating entry"

                # Create entry
                entry             = Entry.new

                entry.user        = User.find(recurring_entry["user_id"])
                entry.reason      = Reason.find_by!(uuid: recurring_entry["reason_uuid"])
                entry.account     = Account.find_by!(uuid: recurring_entry["account_uuid"])

                entry.uuid              = SecureRandom.uuid
                entry.memo              = recurring_entry["memo"]
                entry.date              = current_time
                entry.price             = recurring_entry["price"]
                entry.is_expense        = recurring_entry["is_expense"]
                entry.updated_mobile    = current_time
                entry.reason_uuid       = recurring_entry["reason_uuid"]
                entry.account_uuid      = recurring_entry["account_uuid"]
                entry.project_uuid      = recurring_entry["project_uuid"]

                entry.save!
            end
        end
    end
  end
end

错误日志

Feb 08 04:10:51 taxnote heroku/scheduler.5289:  Starting process with command `bundle exec rake recurring_entry` 
Feb 08 04:10:51 taxnote heroku/scheduler.5289:  State changed from starting to up 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Performing RecurringEntryJob from Inline(default) 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Recurring_Entry_Called 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 102 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 88 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 89 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 92 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 93 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 94 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 95 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 96 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 98 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 97 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 99 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 103 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 104 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 105 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 106 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Recurring_Entry Day of the week check passed for - 106 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Recurring_Entry All cheks passed for - 106 - creating entry 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 107 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 108 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 109 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 110 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 111 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 112 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 113 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 115 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 114 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 87 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 138 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 117 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] “Recurring_Entry Processing for - 118 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Recurring_Entry Day of the week check passed for - 118 
Feb 08 04:10:57 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Recurring_Entry All cheks passed for - 118 - creating entry 
Feb 08 04:10:58 taxnote app/scheduler.5289:  [ActiveJob] [RecurringEntryJob] [88810de1-fffb-4e16-b8f8-17712bc5b084] Performed RecurringEntryJob from Inline(default) in 260.25ms 
Feb 08 04:10:58 taxnote app/scheduler.5289:  rake aborted! 
Feb 08 04:10:58 taxnote app/scheduler.5289:  ActiveRecord::RecordNotFound: Couldn't find Account 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/core.rb:196:in `find_by!' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/app/jobs/recurring_entry_job.rb:42:in `block in perform' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/app/jobs/recurring_entry_job.rb:11:in `perform' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/execution.rb:32:in `block in perform_now' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/i18n-0.7.0/lib/i18n.rb:257:in `with_locale' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/translation.rb:7:in `block (2 levels) in <module:Translation>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:23:in `block (4 levels) in <module:Logging>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:22:in `block (3 levels) in <module:Logging>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `block in tag_logger' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `block in tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:26:in `tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `tag_logger' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:19:in `block (2 levels) in <module:Logging>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_perform_callbacks' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/execution.rb:31:in `perform_now' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/execution.rb:21:in `execute' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/queue_adapters/inline_adapter.rb:14:in `enqueue' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/enqueuing.rb:71:in `block in enqueue' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:14:in `block (3 levels) in <module:Logging>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `block in tag_logger' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `block in tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:26:in `tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/tagged_logging.rb:68:in `tagged' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:43:in `tag_logger' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/logging.rb:13:in `block (2 levels) in <module:Logging>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `instance_exec' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:441:in `block in make_lambda' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:342:in `block in simple' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:497:in `block in around' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:92:in `__run_callbacks__' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_enqueue_callbacks' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/enqueuing.rb:67:in `enqueue' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/activejob-4.2.6/lib/active_job/enqueuing.rb:17:in `perform_later' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/lib/tasks/scheduler.rake:4:in `block in <top (required)>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bugsnag-4.0.2/lib/bugsnag/rake.rb:12:in `execute_with_bugsnag' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `load' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:74:in `kernel_load' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli/exec.rb:27:in `run' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:332:in `exec' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:20:in `dispatch' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/cli.rb:11:in `start' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:34:in `block in <top (required)>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/lib/bundler/friendly_errors.rb:100:in `with_friendly_errors' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/vendor/bundle/ruby/2.3.0/gems/bundler-1.13.7/exe/bundle:26:in `<top (required)>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/bin/bundle:3:in `load' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  /app/bin/bundle:3:in `<main>' 
Feb 08 04:10:58 taxnote app/scheduler.5289:  Tasks: TOP => recurring_entry 
Feb 08 04:10:58 taxnote app/scheduler.5289:  (See full trace by running task with --trace) 
Feb 08 04:10:58 taxnote heroku/scheduler.5289:  State changed from up to complete 
Feb 08 04:10:58 taxnote heroku/scheduler.5289:  Process exited with status 1 

2 个答案:

答案 0 :(得分:1)

您看到的确切错误是什么?

没有看到你得到的错误,Rails可能试图实例化Recurring的所有匹配实例,这比你可用的内存更多。尝试解决此问题的简单方法是使用find_each而不是实例化完整的结果集。这将批量加载匹配的记录(默认值为1000条记录,但您可以将其配置为适合。

Recurring.where(deleted: false).find_each do |recurring|
  # work on recurring
end

由于发生的错误是找不到帐户记录时,您可以添加一些错误处理,如下所示。

Recurring.where(deleted: false).find_each do |recurring|
  # work on recurring
rescue ActiveRecord::RecordNotFound => e
  Rails.logger.error("Account not found: #{recurring.account_uuid}")
  next
end

答案 1 :(得分:0)

我可以通过检查错误日志来解决此问题,这是因为当帐户部分未成立时,它会停止循环。

Repo.update