Reputation: 6805
I would like for some code to run whenever an input file is changed. Here is what I wrote in seed.rake
:
INPUT_FILE = 'input-file'
INPUT_FILE_PROCESSED = '.input-file-processed'
file INPUT_FILE_PROCESSED => [INPUT_FILE, :environment].flatten do
# Expensive code omitted.
touch INPUT_FILE_PROCESSED
end
task all: [INPUT_FILE_PROCESSED]
I thought this would run the expensive code only when INPUT_FILE
was newer than INPUT_FILE_PROCESSED
, but every time I run rake seed:all
, the expensive code runs:
$ rake seed:all
[2 minutes pass]
$ ls -al .input-file-processed input-file
Jul 18 14:56 .input-file-processed
Jul 18 14:12 input-file
$ rake seed:all
[2 minutes pass]
$ ls -al .input-file-processed input-file
Jul 18 15:01 .input-file-processed
Jul 18 14:12 input-file
I am using rake 10.3.1.
Upvotes: 0
Views: 49
Reputation: 66
The dependency on the :environment task screws up the file modification time dependency checking (I imagine this is because the :environment task is always run).
You can depend on just the file and then require the environment manually:
file INPUT_FILE_PROCESSED => INPUT_FILE do
require_relative '../../config/environment'
Upvotes: 1