I implemented a delayed job in my Rails application, following the instructions.
I start the Rails app
I click on a link that launches the delayed job
The job is visible in the database's delayed_jobs table
I run rake jobs:work
The job disappears from the table, so I guess the job has been performed
BUT PROBLEM: /tmp/job.log has not been written (what the job should have done)
The job:
class CsvImportJob
def perform
File.open('/tmp/job.log', 'w') {|f| f.write("Hello") }
end
end
The call:
job = CsvImportJob.new
job.delay.perform
Nothing in the logs.
The rake jobs:work terminal says nothing after its start message:
[Worker(host:nico pid:25453)] Starting job worker
Nothing happen either when I launch the job while rake jobs:work is running.
In contrast, when the line "hello".delay.length is executed, delayed_jobs processes it and a message String#length completed after 0.0556 - 1 jobs processed at 3.6912 j/s, 0 failed does appear.
See https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-undefined_method_xxx_for_class in documentation.
Even delayed_job author don't know the reason. It somehow depends on the webserver you run in on. Try the wiki's recommendation.
See also delayed_job: NoMethodError
I'm a little late to the party, but also look at:
https://github.com/collectiveidea/delayed_job/wiki/Common-problems#wiki-jobs_are_silently_removed_from_the_database
Your case doesn't sound like a YAML deserialization error, but (as the WIKI suggests), you might set Delayed::Worker.destroy_failed_jobs = false so the failed job stays in the table and you can examine the cause of the error.
update
As I think about it: are you sure that the CsvImportJob class is known to the worker task? That is, is csv_import_job.rb defined in one of the "well known" directories for a Rails class? If not, then the worker task won't be able to de-serialize it, which will lead to exactly the behavior that you're seeing.
If for some reason, cav_import_job.rb is not in a well known directory, you can always require it from an initialization file -- that should fix the problem.
Related
I have one Rails app, which uses different databases depending on the domain name (ie. it supports multiple websites). This works by loading up different environments, without issue.
I am trying to figure out how to run the same set of Sidekiq jobs for each of them.
Sidekiq runs on a worker-server instance.
I have tried running a second instance of sidekiq on the commandline of the worker, giving it a different pidfile, logfile, environment and config file.
Problem 1: In the Dashboard, all recurring tasks listed in first instance of sidekiq's config file are gone and only the task from my 2nd instance's config file is there on the recurring jobs tab.
Problem 2: For that job, if I try to enqueue it, I get unitialized constant uninitialized constant JofProductUpdateLive -> I am guessing this is because I defined the class in app/jobs/jof_product_update_live.rb on worker, and it is seeking it on master server ?
Problem 3: If my theory for the error is correct and I place that file on master server, seems to me it will run with environment/db1 and i'm not sure how to run it with db2/environment2 ?
I'm seeking any advice as to how to set something like this up, as I have tried every idea that came my way and as of yet, zero success. I have also combed through every forum I could find on sidekiq to no avail.
Thanks for any help !
Check out the Apartment gem and apartment-sidekiq.
https://github.com/influitive/apartment-sidekiq
I wrote a script to automate Weblogic deployments and during the undeploy and sometimes the deploy part of the script there is an error message that says, "The task cannot be processed further until the current edit session is activated. When this occurs, task processing will continue. The user can exit the deployer tool without affecting the task." When this happens I have to click the "Activate Changes" on the GUI of the admin console for the script to continue and do what I want it to do. Are there any WLST Jython programmers out there that know how to avoid this issue? I am trying to run the script without touching the GUI.
Also, sometimes the State of the managed server changes to 'deploy initializing'. When this happens I know that things are really messed up. I think this happens when I choose the other option "Undo All Changes".
There is a good answer of code for this in this blog
Its best to always do small bits, activate those changes and then proceed to the next task.
When doing an undeploy and deploy, its always better to undeploy, activate the change and then do a deploy and activate again, this way things remain clean else you may have conflicts when activating all changes in 1 go.
and no you dont have to activate from console, you can do from wlst using activate([timeout], [block])
Ensure to commit one transaction per session. This way you would not miss your earlier undeploy/deploy status due to the issue incurred by current deploy/undeploy task. Please find sample code block below.
app-list = [app1 app2 app3 ... app60]
for app in app-list:
edit()
startEdit()
app-path = "<path-to-your-apps>/" + app
deploy(app, app-path, targets=<your-targets>)
print 'deployed ' + app
activate()
I keep running into a recurring issue with my application. Basically, I have certain code that I want it to run when it first starts up the server to check whether certain things have been defined e.g. a schedule, particular columns in the database, existence of files, etc. and then act accordingly.
However, I definitely don't want this code to run when I'm starting a Rake task (or doing a 'generate', etc. For example, I don't want the database fields to be checked under Rake because the Rake task might be the migration to define the fields. Another example, I have a dynamic schedule for Resque but I don't want to load that when starting the Resque workers. And so on and so forth...
And I definitely need the Rake tasks to be loading the environment!
Is there any way of determining how the application has been loaded? I do want to run the code when its loaded via 'rails server', Apache/Passenger, console, etc. but not at other times.
If not, where or how could you define this code to ensure it is only executed in the manner described above?
The easiest way is checking some environment variable in your initialization code with something like
if ENV['need_complex_init']
do_complex_init
end
and running application with need_complex_init=1 rails s
This is my first time using the Ruby on Rails 'clockwork' library. I'm getting the following error when my scheduled job tries to execute:
ERROR -- : uninitialized constant Delayed (NameError)
Here's the code in the job causing the error:
every(1.day, 'Queueing scheduled job', :at => '22:40') { Delayed::Job.enqueue ScheduledJob.new }
I followed Heroku's guide for using 'clockwork' (https://devcenter.heroku.com/articles/clock-processes-ruby), but I'm not entirely sure how the scheduled job is supposed to know what task to execute? Does it know simply because the task itself resides in 'lib/tasks'?
My n00bie gut tells me that the NameError that 'Delayed' is causing is where I should identify the task to run.
Any insight into this would be very much appreciated!
I don't know if you still have that problem. Do you have gem 'delayed_job_active_record' in your Gemfile?. Have you followed the installation step from here:https://github.com/collectiveidea/delayed_job/
Im using Resque + RedisToGo for my background jobs. I am having trouble running background tasks on Heroku. Its strange because, the first time I run a background job, it gets executed without any issues. But when I run it again, it doesnt execute. I would have to run "heroku restart', every other time for a background to complete successfully....
For example. If I have the following code in my Resque background action:
module EncodeSong
#queue = :encode_song
def self.perform(media_id, s3_file_url)
puts 'foobar'
media = Media.find(media_id)
puts 'media id is supposed to be here'
puts media.id
puts s3_file_url
end
end
In "heroku console", I do:
Resque.enqueue(EncodeSong, 26, 'http://actual_bucket_name.s3.amazonaws.com/unencoded/users/1/songs/test.mp3')
In "heroku logs", I can see the 4 "puts", when I run the above code for the first time. But running it a second time, only returns 'foobar'. The other "puts" are not displayed.....
I suspect that it is not able to run "media = Media.find(media_id)", the second time around. This is only happening on the production server on Heroku. On our local development machine, we do not experience this problem.... Anyone know what is wrong?
PS. I have tried enabling Heroku logs, but still don't get any useful response. I have followed this tutorial to set up Heroku with Resque
Seems like your job is failing (probably you're right about the 'media = Media.find' line). Look through the resque admin interface. Look for failed jobs, there you'll find the backtrace of each failed job.
Hope this helps.