Simple rake task generator for oneshot tasks.
$ bin/rails generate oneshot FooBar
create lib/tasks/oneshot/20180205_foo_bar.rake
Then, skeleton file for oneshot rake task will be generated.
# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180205`
namespace :oneshot do
desc ''
task foo_bar_20180205: :environment do
end
end
Add this line to your application's Gemfile:
gem 'oneshot_task_generator', group: :development
And then execute:
$ bundle
# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
config.body = <<-BODY
ActiveRecord::Base.transaction do
# Write transactional code here
end
BODY
end
# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180208`
namespace :oneshot do
desc ''
task foo_bar_20180208: :environment do
ActiveRecord::Base.transaction do
# Write transactional code here
end
end
end
# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
config.arguments = ['task', 'args']
end
# Skeleton for this file was generated by `bin/rails generate oneshot FooBar`
# For copy and paste: `bin/rake oneshot:foo_bar_20180208`
namespace :oneshot do
desc ''
task foo_bar_20180208: :environment do |task, args|
end
end
# config/initializers/oneshot_task_generator.rb
OneshotGenerator.configure do |config|
config.directory = 'your/favorite/directory' # Default: lib/tasks/oneshot
end
Bug reports and pull requests are welcome on GitHub at https://github.com/s-osa/oneshot_task_generator.