2017-02-04 4 views
0

私はRails + Heroku scheduler.rakeで定期的に仕事をしています。複数のオブジェクトをrailsに保存するactiverecord

問題は、あまりにも多くのエントリがある場合、正常に保存されないことです。

すべての保存をエラーなく完了するためにこのコードを変更するにはどうすればよいですか?

この方法は、午前中に一定時間に動作するため、すぐに完了する必要はありませんので、少し遅れて1つずつ保存しても構いません。

おかげで(私はHerokuのウェブと労働者各1倍、25 $ /月を使用しています)!

*は、エラーログで編集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 

答えて

0

アカウントの一部が設立されていなかったとき、それがループを停止したため、私は、エラー・ログをチェックして、この問題を解決することができ、それがあった。

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 date check passed for - #{recurring_entry[:id]}" 

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

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

       # Create entry 
       entry    = Entry.new 
       entry.user  = User.find(recurring_entry["user_id"]) 

       if entry.user.blank? 
        Rails.logger.info "User Blank for - #{recurring_entry[:id]}" 
        next 
       end 

       entry.reason  = Reason.find_by(uuid: recurring_entry["reason_uuid"]) 

       if entry.reason.blank? 
        Rails.logger.info "Reason Blank for - #{recurring_entry[:id]}" 
        next 
       end 

       entry.account  = Account.find_by(uuid: recurring_entry["account_uuid"]) 

       if entry.account.blank? 
        Rails.logger.info "Account Blank for - #{recurring_entry[:id]}" 
        next 
       end 

       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! 

       Rails.logger.info "Recurring_Entry Completed for - #{recurring_entry[:id]}" 
      end 
     end 
    end 
    end 
end 
1

あなたが見ている正確なエラーとは何ですか?

エラーが表示されない場合、Railsは一致するインスタンスRecurringをすべてインスタンス化しようとしている可能性があります。この問題を解決する簡単な方法は、完全な結果セットをインスタンス化するのではなく、find_eachを使用することです。これは1000年、レコードのデフォルトでバッチで一致するレコードを(ロードされますが、あなたはこれが合うように設定することができます。Accountレコードが見つからない場合、あなたには、いくつかを追加することができますされて起こっているエラーとして

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 
+0

申し訳ありませんが、私はeを見つけることができませんでしたこれはrrorログですが、ありがとう、私はこれを試して、それがどうなるか見てみましょう! –

+0

私はsaveメソッドの後にsleep 1を置くことになった、私はそれが動作することを願っています。 –

+0

ログにエラーが発生していますか、それとも静かに失敗していますか?ループはすべてのオブジェクトで実行されますか、またはある時点で失敗しますか? – michaeldever

関連する問題