0

I use gulp to change files of my project.

gulp.task('task1', function(){
    // change file1
});

gulp.task('task2', function(){
    // change file2
});

And if one of the tasks fails (due to error), I need to restore whole project.

So im planning to make a backup, and on err event of gulp, copy backup files to my project.

gulp.on('err', function(err){
    // restore
});

But if someone press Ctrl + C while files are copied, project would not be fully restored. What are the common techniques of restoring?

Artem Svirskyi
  • 7,305
  • 7
  • 31
  • 43
  • Interesting, I haven't seen this workflow ("changing/restoring" files), normally I'd see Gulp used for generating processed files out of some source files. Can you give some more context? – Kos Sep 29 '15 at 08:14
  • @Kos, I update my project to newer version. So project of version 1 got one file structure and project with version 2 other. And I use gulp to automate update process (its global module that uses gulp internally). – Artem Svirskyi Sep 29 '15 at 08:19

1 Answers1

0

Gulp is actually a node process. Node has a variety of events you can bind to. In your case, you will probably want to register your handler to: exit, SIGINT and uncaughtException.

For examples see this answer.

--- edit ---

Following Atrem's comment, it seems like only synch ops will hold (and the documentation state it). To overcome this you might want to spawn a new process to do the shutdown actions you need to do.

Community
  • 1
  • 1
Meir
  • 14,081
  • 4
  • 39
  • 47