ready_to_run sql condition run_at field not able to select any record
chrisliaw opened this issue · 7 comments
Inside the ready_to_run() there is the conditions to select the pending jobs in active record database.
On the adapter of Sqlite, the select statement "(run_at <= ? AND (locked_at IS NULL OR locked_at < ?) OR locked_by = ?) AND failed_at IS NULL" will always return empty result set because of the run_at field is not set correctly. I have no other database installed at the moment to test hence I assume only it affect Sqlite only.
Am I missing anything?
My Gemfile:
Using rake 12.3.2
Using concurrent-ruby 1.1.4
Using i18n 1.5.3
Using minitest 5.11.3
Using thread_safe 0.3.6
Using tzinfo 1.2.5
Using activesupport 5.2.2
Using builder 3.2.3
Using erubi 1.8.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.1
Using rails-dom-testing 2.0.3
Using crass 1.0.4
Using loofah 2.2.3
Using rails-html-sanitizer 1.0.4
Using actionview 5.2.2
Using rack 2.0.6
Using rack-test 1.1.0
Using actionpack 5.2.2
Using nio4r 2.3.1
Using websocket-extensions 0.1.3
Using websocket-driver 0.7.0
Using actioncable 5.2.2
Using globalid 0.4.2
Using activejob 5.2.2
Using mini_mime 1.0.1
Using mail 2.7.1
Using actionmailer 5.2.2
Using activemodel 5.2.2
Using arel 9.0.0
Using activerecord 5.2.2
Using mimemagic 0.3.3
Using marcel 0.3.3
Using activestorage 5.2.2
Using public_suffix 3.0.3
Using addressable 2.6.0
Using io-like 0.3.0
Using archive-zip 0.11.0
Using execjs 2.7.0
Using autoprefixer-rails 9.4.7
Using bindex 0.5.0
Using msgpack 1.2.6
Using bootsnap 1.4.0
Using popper_js 1.14.5
Using rb-fsevent 0.10.3
Using ffi 1.10.0
Using rb-inotify 0.10.0
Using sass-listen 4.0.0
Using sass 3.7.3
Using bootstrap 4.1.3
Using method_source 0.9.2
Using thor 0.20.3
Using railties 5.2.2
Using bootstrap-datepicker-rails 1.8.0.1
Using bundler 1.16.6
Using byebug 11.0.0
Using colorize 0.8.1
Using unf_ext 0.0.7.5
Using unf 0.1.4
Using domain_name 0.5.20180417
Using http-cookie 1.0.3
Using mime-types-data 3.2018.0812
Using mime-types 3.2.2
Using netrc 0.11.0
Using rest-client 2.0.2
Using necromancer 0.4.0
Using equatable 0.5.0
Using tty-color 0.4.3
Using pastel 0.7.2
Using timers 4.3.0
Using tty-cursor 0.6.0
Using tty-screen 0.6.5
Using wisper 2.0.0
Using tty-reader 0.5.0
Using tty-prompt 0.18.1
Using canopus_client 0.1.0 from source at vendor/ext/canopus_client
Using regexp_parser 1.3.0
Using xpath 3.2.0
Using capybara 3.13.2
Using childprocess 0.9.0
Using chromedriver-helper 2.1.0
Using coffee-script-source 1.12.2
Using coffee-script 2.4.1
Using coffee-rails 4.2.2
Using daemons 1.3.1
Using delayed_job 4.1.5
Using delayed_job_active_record 4.1.3
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.2.2
Using distributable 0.1.0 from /Volumes/Stash/08.Dev/Repos/distributable_gem.git (at master@7a9810e)
Using hermes 0.1.0 from source at vendor/ext/hermes_gem
Using multi_json 1.13.1
Using jbuilder 2.8.0
Using jquery-rails 4.3.3
Using ruby_dep 1.5.0
Using listen 3.1.5
Using puma 3.12.0
Using rubyzip 1.2.2
Using tilt 2.0.9
Using sass-rails 5.0.7
Using selenium-webdriver 3.141.0
Using spring 2.0.2
Using spring-watcher-listen 2.0.1
Using sqlite3 1.3.13
Using stateful 0.1.0 from /Volumes/Stash/08.Dev/Repos/stateful_gem.git (at master@f5c6990)
Using turbolinks-source 5.2.0
Using turbolinks 5.2.0
Using uglifier 4.1.20
Using web-console 3.7.0
Using will_paginate 3.1.6
Ruby version : ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]
You cannot use any background processing with Sqlite. Only one process is allowed to have write access to an Sqlite file. You will corrupt that file in short order running any background job processor including DJ.
But, what do you mean by run_at
is not set correctly?
But, what do you mean by
run_at
is not set correctly?
My apologies, I was trying to find a correct sql statement that can return at least a row of record by just select using run_at field. However I tried, I could not select even one row of record regardless how I use Time.now, Time.zone.now, DateTime.now or Time.new etc. The condition just not able to return any result.
The sql statement cannot select any record thereby the job is not triggered anyhow.
If I remove the run_at condition in the ready_to_run() then I can select all the jobs from the database.
Any specific way to do it for Sqlite?
The ready_to_run
condition is correct. How are you queuing the job?
I've got one class inherited from the ApplicationJob with perform() that got the code I need. From model, after_create it trigger the job by calling the class.perform_later(params)
I can see the job data in the table though, just the rake jobs:work doesn't select it out.
If I remove the condition that includes the run_at (datetime field), then the jobs:work is able to select the job out. Since I'm unsure the implication of the run_at field so I inclined to ask it here.
When you are using ActiveJob
you should be following that guide and not delayed job's job structure.