Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 484
Rails beginner Avatar asked Feb 20 '26 07:02

Rails beginner


1 Answers

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.

like image 105
drharris Avatar answered Feb 22 '26 02:02

drharris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!