0

I'm trying to do a cron (with sidekiq-con) on rails to delete all videos uploaded by a user every 20 minutes. Here is my code:

sidekiq.rb :

Sidekiq.configure_server do |config|
    schedule_file = "config/schedule.yml"
    if File.exist?(schedule_file) && Sidekiq.server?
    Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
    end
end

schedule.yml :

clean_video:
  cron: "* * * * *"
  class: "CleanVideoJob"
  queue: default

jobs/clean_video_job.rb :

class CleanVideoJob < ApplicationJob
  queue_as :default

  def perform(*args)
    Video.where(['created_at < ?', 20.minutes.ago]).destroy_all
  end
end

The job queues up every minute on my sidekiq GUI (localhost: 3000 / sidekiq) but nothing happens. I do not really see my problem .. Thank you

  • You say nothing happens. Do you mean the jobs enter the queue but never run, or they are running, but no videos are destroyed? – rmlockerd Jul 06 '21 at 20:06
  • Did you run `bundle exec sidekiq` to start the sidekiq workers? – Hoang Phan Jul 06 '21 at 23:30
  • Yes i see the jobs enter in the queue every minute but they never run. And ofc i have run this command – k1ra444 Jul 07 '21 at 10:07
  • Do other kinds of job run successfully? If you pop open a console and run `CleanVideoJob.perform_later` does the job run? It sounds like either sidekiq isn't running or isn't configured as a backend for ActiveJob. – rmlockerd Jul 08 '21 at 18:36
  • Also, perhaps it would be easier for you to use the gem "arask". It's much simpler to setup. – Esben Damgaard Sep 16 '21 at 08:38

0 Answers0