Delayed Job just not working

delayed-job, mongoid, ruby-on-rails

Solution

`Delayed::Job.enqueue` will put a record in the delayed job table, but you need to run a seperate process to execute the job code (perform method)

typically in development this would be `bundle exec rake jobs:work` (NOTE: you must restart this rake task anytime you make code changes, it will not auto load changes)

- see https://github.com/collectiveidea/delayed_job#running-jobs

I usually put the following into my delayed configuration while in development - this never puts a record in the delayed job table and runs all background code synchronously (in development) and by default rails will reload changes to your code

`Delayed::Worker.delay_jobs = !(Rails.env.test? || Rails.env.development?)`

- https://github.com/collectiveidea/delayed_job#gory-details (see config/initializers/delayed_job_config.rb example section)

Problem

I am building an application where at some point I need to sync a bunch of data from fb with my database, so I am (attemtping) to use Delayed Job to push this into the background. Here is what part of my Delayed Job class looks like. ``` class FbSyncJob < Struct.new(:user_id) require 'RsvpHelper' def perform user = User.find(user_id) FbSyncJob.sync_user(user) end def FbSyncJob.sync_user(user) friends = HTTParty.get( "https://graph.facebook.com/me/friends?access_token=#{user.fb['token']}" ) friends_list = friends["data"].map { |friend| friend["id"] } user.fb["friends"] = friends_list user.fb["sync"]["friends"] = Time.now user.save! FbSyncJob.friend_crawl(user) end end ``` With the `RsvpHelper` class living in `lib/RsvpHelper.rb`. So at some point in my application I call `Delayed::Job.enqueue(FbSyncJob.new(user.id))` with a known valid user. The worker I set up even tells me that the job has been completed successfully: `1 jobs processed at 37.1777 j/s, 0 failed` However when I check the user in the database he has not had his friends list updated. Am I doing something wrong or what? Thanks so much for the help this has been driving me crazy.

Original source