2017-02-04 1 views
0

레일즈 + 헤로큐 스케줄러 .rake로 반복 작업이 있습니다.레일스에 여러 객체 저장 activerecord

너무 많은 항목이있을 때 성공적으로 저장하지 못하는 것이 문제입니다.

오류없이 모든 저장을 완료하려면 어떻게해야합니까?

아침에 고정 된 시간에 작동하므로이 방법을 빨리 완료 할 필요가 없으므로 다소 지연되면 하나씩 저장하는 것이 좋습니다.

감사합니다 (I는 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

I 오류 로그를 확인하여이 문제를 해결할 수는 있었다.

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 개 개의 레코드의 기본값은 일괄 적으로 일치하는 기록을 (로드,하지만 당신은이에 맞게 구성 할 수 있습니다. 계정 레코드를 찾을 수 없을 때, 당신은 몇 가지를 추가 할 수 있습니다 일어나는 오류로

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

미안 해요, 전자를 찾지 못했습니다. rror log for this,하지만 고마워, 나는 이것을 시도하고 그것이 어떻게되는지 보게 될 것이다! –

+0

저장 방법을 마친 후에 수면을 끝내기 시작 했으므로 효과가 있기를 바랍니다. –

+0

로그에 오류가 있습니까? 아니면 자동으로 오류가 있습니까? 루프가 모든 개체에서 실행됩니까? 아니면 어느 시점에서 루프가 실패합니까? 저장하려고하는 객체가 '유효합니까?' – michaeldever

관련 문제