0

I have a few files in a project that require post-processing each time they are updated.

I can extract these processes into a rake task. My question is:

How can a rake task be run automatically every time a specific file is saved?

sscirrus
  • 55,407
  • 41
  • 135
  • 228

2 Answers2

0

I think you will be able to do this using invoke method

if @file.save
  .
  .
  .
  Rake::Task['task_name'].invoke
end

see this SO question for more info

Community
  • 1
  • 1
Tony Vincent
  • 13,354
  • 7
  • 49
  • 68
0

You can do this in your model file.

  after_save :update_rake_operations

  def update_rake_operations
    task = "update_status"
    Rake::Task[task].invoke
  end

You should have the below code in Rakefile under project folder. This should be present by default.

  require File.expand_path('../config/application', __FILE__)
  require 'rake'

  ProjectFolder::Application.load_tasks
Bijendra
  • 9,467
  • 8
  • 39
  • 66