Rails beginner
Rails beginner

Reputation: 14514

How to call a rake task inside controller?

How do I call a rake task in an controller?

I need it to a delayed job.

Upvotes: 3

Views: 5464

Answers (2)

John Hex Carter
John Hex Carter

Reputation: 56

If you need cron jobs within Ruby I highly recommend the whenever gem

Upvotes: 0

drharris
drharris

Reputation: 11204

Rake::Task['task_name'].invoke(args)

But, I'd recommend against this; it's bad practice. It's better to either use Cron if you need that type of functionality, or you can use delayed_job with a custom job object specific to your needs. I'd personally recommend the latter as it causes less pain when moving servers. But delayed_job is not built to run rake tasks, it's meant to queue work items that you create.

Upvotes: 6

Related Questions