I'm trying to understand how to use Shake
and how to build new rules. As an exercise, I've decided to implement what I call a backup
rule.
The idea is to generate a file if it doesn't exists OR if it's too old (let's more than 24 hour). I like to store long command in a makefile and run them on demand. An example is a mysql backup. The only problem is when the backup already exists, make
doesn't do anything. To solve this, I can either
- remove the previous backup before redoing a new one,
- make the backup target
phony
- add a fictive
force
dependency, which I can touch manually or in cron.
What I would like, is to redo the backup if it's older than 24 hours (which I can do with a touch force
in cron). Anyway it's only an example to play with Shake
. What I would like is something like :
expirable "my_backup" 24 \out -> do
cmd "mysqldump" backup_parameter out
I read the doc, but I have no idea how to do this or define a rule and what an Action
is.
I understand that I need to instanciate a Rule
class but I can't figure out what is what.
Clarification
I don't want the backup to be run automatically but to be run only on demand but with a maximum of once per 24 hour.
An example scenario is I have a production database on a remote machine, local copy and run some time consuming reports locally. The normal workflow is
- download production backup
- refresh the local database with it
- create some denormalized tables on a local warehouse database
- generate some report.
I don't run the report every days but only when I need it. So I don't want to run report every 24 hours. It's easy to do with a makefile except the timing bit, they are wor around but once again it's a contrived example to understand deeply how Shake work.
So, when I first do make report
it backup the db run everything and generate the report.
Now, I want to modify the report (because I'm testing it). I don't need the backup to regenerated (nor the local database to refreshed) (we are the evening, and I know that nothing has changed on production until the next day)
Then the next day, or next month, I rerun the report. This time I need the backup to be done again, and all it's dependency to be rerun as well.
Basically the rule I need is instead of
redo timestamp = timestamp < old
is
redo timestamp = timestamp < old || now > timestamp + 24*36000
But I have no idea where to put this rule.
The question is more where to puth it, instead of how to write it (it's above). If it's easier (to explain) I can have a rule which ask the user (getLine) 'do you want to redo the this target (yes/no)?`.
Later I will also need a rule depending on the last update of the database (or a specific table). I know how to get the information from the database but not how to integrate it in Shake.
I might be confused with what a Rule
is. In make a rule is about how to make a target (so it's more a recipe) or what I think is the Action in Shake. Where is, when I say rule, I mean the rule which decide to remake the target or not, not how to do it. In make, you don't have the choice (it's timestamp) so there is no such concept.