Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No log when run on que CLI #310

Closed
drselump14 opened this issue Jul 5, 2021 · 3 comments
Closed

No log when run on que CLI #310

drselump14 opened this issue Jul 5, 2021 · 3 comments

Comments

@drselump14
Copy link

I can't find any log when running the worker with que CLI

bundle exec que --log-level debug -q default --log-internals
Que waiting for jobs...

Adding a job works fine, and workers picked up the job but no information on the log.

Did I miss something?

This is my job

module TradeContracts
  class ReviseWhenExpiredJob < ApplicationJob
    extend T::Sig
    queue_as :default

    sig { params(trade_contract: TradeContract).returns(T.untyped) }
    def perform(trade_contract:)
      return unless should_execute?(trade_contract)

      TradeContract::Operation::AutomaticRevise.call(model: trade_contract)
    end

    sig { params(trade_contract: TradeContract).returns(T::Boolean) }
    def should_execute?(trade_contract)
      trade_contract.may_revise? && trade_contract.expiration_job_id.present?
    end
  end
end
job = TradeContracts::ReviseWhenExpiredJob.set(wait_until: 30.seconds.from_now).perform_later(trade_contract: t)
# Gemfile
gem "que", "~> 1.0.0.beta4"
gem "que-scheduler"
gem "que-web"

The Que::Job format didn't work either.

@ZimbiX
Copy link
Member

ZimbiX commented Jul 6, 2021

See the logging section of the docs.

We use a logging middleware:

# frozen_string_literal: true

module DexProviderBridge
  module Que
    module JobMiddleware
      class Logging
        def initialize(logger:)
          @logger = logger
        end

        def call(job)
          job_args = args(job)

          logger.info("Starting #{job.job_name} job", **job_args)

          before = Time.now.getutc

          yield

          duration = '%.2f' % (Time.now.getutc - before)

          logger.info("Finished #{job.job_name} job in #{duration}s", **job_args)
        end

        private

        def args(job)
          job.que_attrs[:args].reduce({}, :merge)
        end

        attr_reader :logger
      end
    end
  end
end
middlewares = [
  DexProviderBridge::Que::JobMiddleware::Logging.new(logger: app['logger']),
  # ...
]
middlewares.each do |middleware|
  Que.job_middleware.push(middleware)
end

@oeoeaio
Copy link
Contributor

oeoeaio commented Mar 15, 2022

Closing this now @drselump14, feel free to re-open if still an issue.

@oeoeaio oeoeaio closed this as completed Mar 15, 2022
@pcantrell
Copy link

For anyone who's blocked waiting for a fix for this to upgrade Rails, here is a terrible hack that makes the error disappear. BEWARE: This may do terrible things; it's just a monkey patch that applies the fix in #423, and I have no idea whether it's a good idea.

In config/initializers/que.rb:

# Temporary workaround for https://github.com/que-rb/que/issues/425
# until Que merges https://github.com/que-rb/que/pull/423 or similar
unless ::ActiveRecord::Base.respond_to?(:clear_active_connections!)
  class ::ActiveRecord::Base
    def self.clear_active_connections!
      ::ActiveRecord::Base.connection_handler.clear_active_connections!(:all)
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants