Reputation: 10631
I have a rubyscript in /myapp/scripts/myscript.rb
when i run ruby script/myscript.rb
it executes fine, but how do I run this method with delayed job from within a ruby script? Hope this makes sense
---myscript.rb---
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
def populate
#do some stuff here
end
handle_asynchronously :populate
I get a undefined method 'handle_asynchronously' error
Upvotes: 0
Views: 126
Reputation: 9722
I think handle_asynchronously works only on methods and not on top-level functions. Maybe you can declare a module like this:
# scripts/myscript.rb
class Tasks
def populate
puts "Populating..."
end
handle_asynchronously :populate
end
# call it in some function
def my_user_task
Tasks.new.populate
end
Upvotes: 1