Rails Runner or Rake task can't trigger Active Job job - ruby-on-rails

I have setup a Rails 7 project running in Docker. Using the whenever gem (using cron) I tried to execute either
a rails runner task
a rake task
Both shall do the same thing: call a class method WebpageChangeCheck.check_all which itself calls a method of a model. Which then creates an Active Job job. But both fail in the final step to create the job:
app/cron_jobs/webpage_change_check.rb:
class WebpageChangeCheck
def self.check_all
Webpage.all.each do |page|
if page.checking_active
page.check_for_change
end
end
end
end
app/models/webpage.rb:
def check_for_change
self.update(counter: self.counter += 1)
UpdateOffersHashJob.perform_later(self)
end
update_offers_hash_job.rb:
class UpdateOffersHashJob < ApplicationJob
queue_as :default
require 'nokogiri'
require 'open-uri'
require 'net/http'
after_perform do |job|
compare_hashes(job.arguments.first)
end
def perform(page)
page.update(offers_hash_old: page.offers_hash_new)
all_offers = ""
doc = Nokogiri::HTML(URI.open(page.url))
doc.css(page.selector).each do |offer|
all_offers += offer.to_s
end
page.update(offers_hash_new: all_offers.delete(" \t\r\n\ "))
end
private
def compare_hashes(page)
...
end
end
What works:
calling the same class method from rails console creates the Active Job as expected. I get the following output:
irb(main):002:0> WebpageChangeCheck.check_all
Webpage Load (1.2ms) SELECT "webpages".* FROM "webpages"
Webpage Update All (3.9ms) UPDATE "webpages" SET "counter" = COALESCE("counter", 0) + $1 WHERE "webpages"."id" = $2 [["counter", 1], ["id", 1]]
Enqueued UpdateOffersHashJob (Job ID: 707e164d-b8b9-407b-aa35-4b23c37b4f07) to Async(default) with arguments: #<GlobalID:0x00007f2e0b7c4878 #uri=#<URI::GID gid://my_rails_app/Webpage/1>>
=>
[#<Webpage:0x00007f2e0b7bded8
id: 1,
title: "example.com",
url: "https://www.example.com",
user_id: 1,
created_at: Wed, 18 Jan 2023 14:22:51.904097000 CET +01:00,
updated_at: Fri, 20 Jan 2023 00:12:02.749748000 CET +01:00,
interval: 1,
checking_active: true,
selector: ".headline_content",
counter: 386>]
Webpage Load (0.6ms) SELECT "webpages".* FROM "webpages" WHERE "webpages"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Performing UpdateOffersHashJob (Job ID: 707e164d-b8b9-407b-aa35-4b23c37b4f07) from Async(default) enqueued at 2023-01-20T07:26:02Z with arguments: #<GlobalID:0x00007f2e092e1088 #uri=#<URI::GID gid://my_rails_app/Webpage/1>>
TRANSACTION (0.2ms) BEGIN
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
irb(main):003:0> TRANSACTION (1.0ms) COMMIT
TRANSACTION (0.4ms) BEGIN
Webpage Load (0.6ms) SELECT "webpages".* FROM "webpages" WHERE "webpages"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Sim Create (1.4ms) INSERT INTO "sims" ("to", "time", "api_response", "success", "webpage_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["to", 49123456789], ["time", nil], ["api_response", nil], ["success", nil], ["webpage_id", 1], ["created_at", "2023-01-20 07:26:03.108189"], ["updated_at", "2023-01-20 07:26:03.108189"]]
TRANSACTION (3.5ms) COMMIT
TRANSACTION (0.4ms) BEGIN
Sim Update (1.0ms) UPDATE "sims" SET "time" = $1, "api_response" = $2, "success" = $3, "updated_at" = $4 WHERE "sims"."id" = $5 [["time", "Fri, 20.01.23 - 08h26 03s"], ["api_response", "100\nVerbucht: 0\nPreis: 0.075\nGuthaben: 0.35\nText: ALERT\nSMS-Typ: direct\nFlash SMS: false\nEncoding: gsm\nGSM0338: true\nDebug: true"], ["success", true], ["updated_at", "2023-01-20 07:26:03.295980"], ["id", 22]]
TRANSACTION (3.8ms) COMMIT
Performed UpdateOffersHashJob (Job ID: 707e164d-b8b9-407b-aa35-4b23c37b4f07) from Async(default) in 585.89ms
What I see from bash (from rake or rails runner) the Active Job gets created but it will not perform:
root#f77855c949a8:/opt/app# rake debug check_all_pages
Webpage Load (1.5ms) SELECT "webpages".* FROM "webpages"
↳ app/cron_jobs/webpage_change_check.rb:4:in `check_all'
Webpage Update All (2.9ms) UPDATE "webpages" SET "counter" = COALESCE("counter", 0) + $1 WHERE "webpages"."id" = $2 [["counter", 1], ["id", 1]]
↳ app/models/webpage.rb:9:in `check_for_change'
[ActiveJob] Enqueued UpdateOffersHashJob (Job ID: f4495cb8-868f-4ed5-9f03-7f4407b5efa4) to Async(default) with arguments: #<GlobalID:0x00007fd55771ece0 #uri=#<URI::GID gid://my_rails_app/Webpage/1>>
root#f77855c949a8:/opt/app#
here you also go with the rake task:
my_rails_app/lib/tasks/checker_task.rake:
desc "checks all Webpages for changes. Called from cronjob."
task check_all_pages: :environment do
WebpageChangeCheck.check_all
end
Conclusion:
it seems like the environment loaded properly, including environment variables. I have access to my classes and models.
nevertheless there seems to be a difference which prevents the Job from being performed.
part of the problem might be there is not enough logging to debug it, so this could be improved as well!
Any ideas?
Thanks a lot!

You need to process your job queue in another process, e.g.
rake jobs:work

So, thanks to the help in the comments I realized I overlooked to install the delayed_job backend/processing queue incl. db table for Active Job cause I thought this comes with it. It is needed to enqueue and work off the jobs. Not suitable for large amounts of jobs but sufficient for my purpose.
Here is a complete guide:
https://axiomq.com/blog/deal-with-long-running-rails-tasks-with-delayed-job/
You can also check these docs:
https://guides.rubyonrails.org/active_job_basics.html
https://github.com/collectiveidea/delayed_job#active-job
Short version:
I added the gem 'delayed_job_active_record'
Add and execute
bundle install
config/application.rb:
config.active_job.queue_adapter = :delayed_job
rails generate delayed_job:active_record
rails db:migrate
rails jobs:work
As mentioned, this is a seperate process that has to be run.
Question remains why the job performs when being run through rails console. Maybe it won't queue then but execute rightaway ..

Related

Rails - Devise's registration controller create action seems to trigger twice

I added this lines of code to create action:
def create
super
#card = Card.find(params[:card_id])
#card.update(:user_id=>current_user)
end
And everything works fine, user gets created, card gets updated, but after redirect this happens:
Couldn't find Card with 'id'=
Extracted source (around line #14):
def create
super
#card = Card.find(params[:card_id])
#card.update(:user_id=>current_user)
end
I checked my terminal to find out the reason why this happens, and it seems that create action triggers twice for no reason:
Started POST "/users" for ::1 at 2020-08-12 11:04:34 +0300
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"q1W0+ZhzK85uHTcp1x4jKHvCG0ukIgj2JxZuAy6vuLQl/vPqJVu6eXSEWviYTnWC4cXAJk2xCJhl8mgoWzXIAA==", "user"=>{"name"=>"Терл Кабот", "email"=>"tafff1#gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "card_id"=>"2000012606"}, "commit"=>"Sign up"}
Card Load (1.0ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = $1 LIMIT $2 [["id", 2000012606], ["LIMIT", 1]]
(0.0ms)
BEGIN
User Exists (1.0ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2 [["email", "tafff1#gmail.com"], ["LIMIT", 1]]
SQL (1.0ms) INSERT INTO "users" ("email", "encrypted_password", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["email", "tafff1#gmail.com"], ["encrypted_password", "$2a$12$qTrv/zFUxULi9sqWgYlY/uPjQoJsZxB8PJK2ae/e6YfAFT40ci47e"], ["name", "Терл Кабот"], ["created_at", "2020-08-12 08:04:35.174621"], ["updated_at", "2020-08-12 08:04:35.174621"]]
SQL (1.0ms) UPDATE "cards" SET "user_id" = $1, "updated_at" = $2 WHERE "cards"."id" = $3 [["user_id", 17], ["updated_at", "2020-08-12 08:04:35.178626"], ["id", 2000012606]]
(1.0ms) COMMIT
Redirected to http://localhost:3000/
Card Load (0.0ms) SELECT "cards".* FROM "cards" WHERE "cards"."id" = $1 LIMIT $2 [["id", nil], ["LIMIT", 1]]
Completed 404 Not Found in 378ms (ActiveRecord: 6.0ms)
ActiveRecord::RecordNotFound (Couldn't find Card with 'id'=):
is there any solution for this?
EDIT: I gave up and just changed card and user logic, now user belongs to card, so I dont have to update cards user_id from devises create action.
The card_id is nested in the user key, so it will be: params[:user][:card_id]

Rails NoMethodError (undefined method `humanize' for nil:NilClass) in mail to:

I have such job in my Rails app:
class NewAnswerNotifyJob < ApplicationJob
queue_as :default
def perform(answer)
Services::NewAnswerNotify.new.send_notify(answer)
end
end
Services::NewAnswerNotify:
class Services::NewAnswerNotify
def send_notify(answer)
NewAnswerNotifyMailer.new.notify(answer)
end
end
NewAnswerNotifyMailer:
class NewAnswerNotifyMailer < ApplicationMailer
def notify(answer)
#answer = answer
#question = answer.question
#author = answer.question.author
mail to: #author.email
end
end
When I try in Rails console (I faced with this problem on a dev server, then have replayed this behavior in console) to run Services::NewAnswerNotify#send_notify with an answer I got such error:
2.6.0 :023 > answer = Answer.first
Answer Load (0.5ms) SELECT "answers".* FROM "answers" ORDER BY "answers"."best_solution" DESC LIMIT $1 [["LIMIT", 1]]
=> #<Answer id: 76, body: "answer body", question_id: 2, created_at: "2019-05-01 18:43:16", updated_at: "2019-05-28 15:38:16", author_id: 1, best_solution: true>
2.6.0 :024 > Services::NewAnswerNotify.new.send_notify(answer)
Question Load (0.6ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Traceback (most recent call last):
3: from (irb):24
2: from app/services/new_answer_notify.rb:3:in `send_notify'
1: from app/mailers/new_answer_notify_mailer.rb:8:in `notify'
NoMethodError (undefined method `humanize' for nil:NilClass)
2.6.0 :025 >
So, the error occurs in mail to: #author.email line in NewAnswerNotifyMailer, but when but itself mailer works as planned:
2.6.0 :025 > answer = Answer.first
Answer Load (0.7ms) SELECT "answers".* FROM "answers" ORDER BY "answers"."best_solution" DESC LIMIT $1 [["LIMIT", 1]]
=> #<Answer id: 76, body: "for flexbox grid columns also means you can set th...", question_id: 2, created_at: "2019-05-01 18:43:16", updated_at: "2019-05-28 15:38:16", author_id: 1, best_solution: true>
2.6.0 :026 > NewAnswerNotifyMailer.notify(answer)
Question Load (0.5ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
[i18n-debug] en.new_answer_notify_mailer.notify.subject => nil
Rendering new_answer_notify_mailer/notify.html.slim within layouts/mailer
Rendered new_answer_notify_mailer/notify.html.slim within layouts/mailer (4.7ms)
Rendering new_answer_notify_mailer/notify.text.slim within layouts/mailer
Rendered new_answer_notify_mailer/notify.text.slim within layouts/mailer (3.5ms)
NewAnswerNotifyMailer#notify: processed outbound mail in 100.5ms
=> #<Mail::Message:70164808395160, Multipart: true, Headers: <From: from#example.com>, <To: codcore#gmail.com>, <Subject: Notify>, <Mime-Version: 1.0>, <Content-Type: multipart/alternative; boundary="--==_mimepart_5d0cac2d80291_b85a3fd081039fd052340"; charset=UTF-8>>
I can't realize where problem is, why I get Nil at the Services::NewAnswerNotify.
Several suggestions:
You should use ActionMailer class methods directly instead of instantiating a new mailer with new. This is probably the source of the bug
Since your NewAnswerNotify is nested under Services, it would also make it less ambiguous to use the root namespace ::NewAnswerNotifyMailer (some people may disagree with me on this one, but I've had so many root namespace bugs in the past that I tend to systematically use the :: prefix now)
Beware of class loading that works differently for class Services::NewAnswerNotify and module Services class NewAnswerNotification (lots of existing questions on this topic)
module Services
class NewAnswerNotify
def send_notify(answer)
::NewAnswerNotifyMailer.notify(answer).deliver_now # instead of .new.notify
end
end
end
Also some side comments regarding the variables and the english
I would rather use
Services::NewAnswerNotification
NewAnswerNotificationMailer
def send_notification(answer) or def notify(answer)
And maybe one last piece of advice from experience after maintaining a code base in the long run: to be more explicit regarding who you are notifying of what def notify_question_author_of_new_answer because later you might have a notify_question_subscribers_of_new_answer or someone else who might need to be notified (it totally depends on your business model of course, feel free to ignore this remark)

Cannot access user model from Devise sessions controller: [merit] no target_obj found on Rule#applies?

I have
class CustomSessionsController < Devise::SessionsController
def create
#user = resource # needed for Merit
super
end
protected
def after_sign_in_path_for(resource)
#user = resource # needed for Merit
resource.update_streak
super
And
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, model_name: 'User' do |user|
puts user.inspect
user.streak.count >= 3
end
But it gives the error
[merit] no target_obj found on Rule#applies?
And I can't access the model and it doesn't grant the badge or log the user. What is wrong? I followed the guide.
https://github.com/merit-gem/merit/wiki/How-to-grant-badges-on-user-using-Devise
It's doing something.
Processing by CustomSessionsController#create as HTML
Parameters: {"utf8"=>"√", "authenticity_token"=>"gqUQjF9hfzJdQqxAAQJxv7bi+kZYwuv1NWtOP0YhkbjHKwnfa5WAb/CkRZ5c+Xi5yVlnJ2v774w3XLhTa1b1sQ==", "user"=>{"email"=>"student#gmail.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
User Load (6.0ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "student#gmail.com"]]
(7.0ms) BEGIN
SQL (3.0ms) UPDATE "users" SET "last_sign_in_at" = $1, "current_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5 [["last_sign_in_at", "2018-08-09 05:38:58.345271"], ["current_sign_in_at", "2018-08-10 01:40:51.644592"], ["sign_in_count", 15], ["updated_at", "2018-08-10 01:40:51.668609"], ["id", 3]]
(25.0ms) COMMIT
Streak Load (21.0ms) SELECT "streaks".* FROM "streaks" WHERE "streaks"."user_id" = $1 LIMIT 1 [["user_id", 3]]
Redirected to http://localhost:3000/
(1.0ms) BEGIN
SQL (7.0ms) INSERT INTO "merit_actions" ("user_id", "action_method", "target_model", "target_data", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["user_id", 3], ["action_method", "create"], ["target_model", "custom_sessions"], ["target_data", "--- \n...\n"], ["created_at", "2018-08-10 01:40:53.539847"], ["updated_at", "2018-08-10 01:40:53.539847"]]
(8.0ms) COMMIT
Merit::Action Load (6.0ms) SELECT "merit_actions".* FROM "merit_actions" WHERE "merit_actions"."processed" = $1 [["processed", "f"]]
(3.0ms) BEGIN
SQL (2.0ms) UPDATE "merit_actions" SET "processed" = $1, "updated_at" = $2 WHERE "merit_actions"."id" = $3 [["processed", "t"], ["updated_at", "2018-08-10 01:40:53.581875"], ["id", 17]]
(20.0ms) COMMIT
User Load (2.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
[merit] no target_obj found on Rule#applies?
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
[merit] no target_obj found on Rule#applies?
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
Completed 302 Found in 2567ms (ActiveRecord: 293.2ms)
Merit 2.4, Rails 4.2.
I tried
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true do
puts current_user.inspect
current_user.streak.count >= 3
end
But it gave
[merit] no target found: uninitialized constant CustomSession. base_target_finder.rb:13:in 'find'
error NameError (undefined local variable or method 'current_user'
I tried
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, to: :itself do |user|
puts user.inspect
user.streak.count >= 3
end
def create
#custom_session = resource # needed for Merit
def after_sign_in_path_for(resource)
#custom_session = resource # needed for Merit
But it gave
[merit] no target found: uninitialized constant CustomSession. C:/ruby23/lib/ruby/gems/2.3.0/gems/merit-2.4.0/lib/merit/base_target_finder.rb:13:in `find'
true
Completed 500 Internal Server Error in 2181ms (ActiveRecord: 177.1ms)
NoMethodError (undefined method `streak' for true:TrueClass):
app/models/merit/badge_rules.rb:43:in `block in initialize'
I got it working with
grant_on 'custom_sessions#create', badge: :streak, level: 3, temporary: true, model_name: 'User', to: :itself do |user|
def create
super
#custom_session = resource # needed for Merit
But I don't know why because the /users/sign_in path does not have an :id parameter.
https://github.com/merit-gem/merit#how-merit-finds-the-target-object
Merit would fetch the Article object from the database, found by the :id param sent in that update action.

Rspec's expect change count not working

Here I'm testing the changes in current_user.messages.count after the current user sends a valid message. Here's my code:
spec
scenario 'adds to their messages', js: true do
expect { find('#message_content').send_keys(:enter) }.to \
change(current_user.messages, :count).by(1)
end
test.log
# ...
ConversationChannel is transmitting the subscription confirmation
ConversationChannel is streaming from conversation_channel_1
(0.6ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."user_id" = $1 [["user_id", 1]]
ConversationChannel#send_message({"content"=>"foobar\n", "conversation_id"=>"1"})
(0.3ms) BEGIN
(0.9ms) SELECT COUNT(*) FROM "messages" WHERE "messages"."user_id" = $1 [["user_id", 1]]
Conversation Load (1.6ms) SELECT "conversations".* FROM "conversations" WHERE "conversations"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
(0.7ms) SELECT "users"."id" FROM "users" INNER JOIN "user_conversations" ON "users"."id" = "user_conversations"."user_id" WHERE "user_conversations"."conversation_id" = $1 [["conversation_id", 1]]
SQL (1.0ms) INSERT INTO "messages" ("content", "user_id", "conversation_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["content", "foobar\n"], ["user_id", 1], ["conversation_id", 1], ["created_at", "2018-01-29 11:27:13.095277"], ["updated_at", "2018-01-29 11:27:13.095277"]]
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2018-01-29 19:27:13 +0800
ConversationChannel stopped streaming from conversation_channel_1
(0.2ms) BEGIN
(58.8ms) COMMIT
(16.7ms) ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "ar_internal_metadata" DISABLE TRIGGER ALL;ALTER TABLE "conversations" DISABLE TRIGGER ALL;ALTER TABLE "messages" DISABLE TRIGGER ALL;ALTER TABLE "user_conversations" DISABLE TRIGGER ALL;ALTER TABLE "users" DISABLE TRIGGER ALL
Rendered messages/_message.html.erb (0.6ms)
[ActionCable] Broadcasting to conversation_channel_1: {:message=>"<p>User 1: foobar\n</p>\n"}
# ...
The spec fails expected #count to have changed by 1, but was changed by 0 even though in the log shows INSERT INTO actually happen.
This doesn't work because you're not waiting long enough for the message addition to actually occur. send_keys returns as soon as the browser has been sent the key event, but knows nothing at all about any request/action triggered by that key press in the browser. This is why direct DB access tests are generally a bad idea in feature/system tests (which should generally just test user visible changes/interactions) and make more sense as request or controller.
That being said you could fix this by just sleeping after sending the key, but a better solution is to use one of the Capybara provided matchers (have waiting/retrying behavior) to synchronize the test.
scenario 'adds to their messages', js: true do
expect do
find('#message_content').send_keys(:enter) }
expect(page).to have_css(...) # check for whatever visible change on the page indicates the action triggered by send_keys has completed
end.to change { current_user.reload.messages.count }.by(1)
end
Note: This test is also very simple for a feature test. It's okay to have multiple expectations in a feature test since it's really meant to test a whole user interaction with a specific feature of your app. You might want to look at combining this test with other tests of the same part of your app.
Try to write :
change{current_user.messages, :count}.by(1)
with {}

delayed job not performing after being enqued, rails

I did this in controller:
MyTestJob.perform_later
When this is called, this is displayed in my rails console:
[ActiveJob] Enqueued MyTestJob (Job ID: e7af2684-4dc4-4a1f-bac7-b189dddb6f2f) to DelayedJob(default)
[ActiveJob] (0.4ms) BEGIN
[ActiveJob] SQL (0.6ms) INSERT INTO "public"."delayed_jobs" ("queue", "handler", "run_at", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["queue", "default"], ["handler", "--- !ruby/object:ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper\njob_data:\n job_class: GenerateCouponcodesJob\n job_id: e7af2684-4dc4-4a1f-bac7-b189dddb6f2f\n queue_name: default\n arguments: []\n"], ["run_at", "2015-10-28 09:58:17.891850"], ["created_at", "2015-10-28 09:58:17.892095"], ["updated_at", "2015-10-28 09:58:17.892095"]]
[ActiveJob] (11.0ms) COMMIT
Rendered campaign/test.html.erb within layouts/application (0.1ms)
Completed 200 OK in 254ms (Views: 233.6ms | ActiveRecord: 12.0ms)
SO the above log says that job is enqued (which proves my delayed job worker is working fine), but it is not getting performed,
here is my job:
class MyTestJob < ActiveJob::Base
queue_as :default
def perform(*args)
directory = Rails.root
File.open(File.join(directory, 'file.txt'), 'w') do |f|
f.puts "contents"
end
Delayed::Worker.logger.debug("Log Entry")
end
end
No file created and no log created in delayed_job.log.
I have done everything correctly but still, there are no error as well...
the above log says that job is enqueued (which proves my delayed job worker is working fine)
Nope. This means that the "enqueuer" is working fine. Says nothing about the worker.
It should be run as a separate process.
bundle exec rake jobs:work

Resources