Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

In production Sidekiq add job to history, but doesn't execute it (Sidekiq + Redis + EC2 + Cloud66)

$
0
0

My app have an import function that'll execute a Sidekiq Worker and import a bunch of CSV rows, saving them to my database. This works fine when I execute Sidekiq in my local machine, but when I deploy the code to production Sidekiq will execute the job correctly only once. When I use the import function a second time the job goes directly to the history pile in Sidekiq, and the logic inside the worker is never executed. It's really strange because it throws no error and it's like the job was executed correctly. For staging I'm using Redis in AWS Elastic Cache.

redis_version: 5.0.6rails, "5.0.7"sidekiq, "6.0.5"sidekiq-failures, "1.0.0"sidekiq-history, "0.0.11"sidekiq-limit_fetch, "3.4.0"sidekiq-pro, "5.0.1"sidekiq-unique-jobs, "6.0.15"

I would appreciate any tips related to problems you faced before similar to this, or anything else I can do to debug this problem. I already ran

Sidekiq.redis { |conn| conn.ping }=> "PONG"

So looks like Redis is connected ok.

Project Worker

# frozen_string_literal: trueclass ImportWorker  include Sidekiq::Worker  sidekiq_options queue: "import_worker", lock: :until_executed, retry: false  def perform(import_id)    import = Import.find_by(id: import_id)    return if import.blank?    path = import.file.expiring_url(10)    file = open(path)    csv = CSV.parse(file.read, headers: true)    import.update!( number_of_lines_in_csv: csv.size,                    import_started_at: DateTime.now)    created_transactions = []    csv.each do |row|      guid = row["TransactionUniqueId"]      next if guid.blank?      existing_transaction = Transaction.find_by(transaction_unique_id: guid)      next if existing_transaction.present?      attributes = Transaction.convert_attributes(import, row).merge(imported_at: Time.now)      transaction = Transaction.create!(attributes)      created_transactions << [transaction.id, guid]      Rails.logger.info "Transaction #{row["TransactionUniqueId"]} created."    end    import.update!(import_finished_at: DateTime.now,                   imported:           true)    send_mail(import_id, created_transactions)  end  def send_mail(import_id, created_transactions)    ["email0@example.com", "email1@example.com"].each do |email|      ImportTransactionsMailer.import_processed(import_id, email, created_transactions).deliver    end  endend

Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>