1

In my Rails 4.2 app, I'm using sitemap_generator gem to generate sitemaps. And use Heroku scheduler to execute the rake task. I think it'd be better if the sitemap is generated when there is new content or execute a manual action from admin panel by clicking a button to generate sitemap and ping search engines.

So, in my ActiveJob, I'm executing following in background Job Rake::Task['sitemap:refresh'].invoke

But it gives me the error that it doesn't know, how to build this task.

RuntimeError: Don't know how to build task 'sitemap:refresh' (see --tasks)

Thanks,

lightsaber
  • 1,481
  • 18
  • 37

1 Answers1

1

Seems like the issue is the rake tasks are not loaded. You can first load the tasks and then invoke. Something listed below should help:

NameOfYourApp::Application.load_tasks
Rake::Task['sitemap:refresh'].invoke
PaulDaviesC
  • 1,161
  • 3
  • 16
  • 31
  • this code didn't work for me i got this error ```RuntimeError Don't know how to build task 'sitemap:refresh' (See the list of available tasks with `rake --tasks`)``` – Daniel Ansari Feb 21 '22 at 15:53