NAME

Stepford::Role::Step::FileGenerator::Atomic - A role for steps that generate a file atomically

VERSION

version 0.006001

DESCRIPTION

This role consumes the Stepford::Role::Step::FileGenerator role. It allows only one file production, but makes sure it is written atomically - the file will not exist if the step aborts. The file will only be committed to its final destination when run completes successfully.

Instead of manipulating the file production directly, you work with the file given by $step->pre_commit_file. This role will make sure it gets committed after run.

METHODS

This role provides the following methods:

$step->BUILD

This method adds a wrapper to the BUILD method which ensures that there is only one production.

$step->pre_commit_file

This returns a temporary file in a temporary directory that you can manipulate inside run. It will be removed if the step fails, or renamed to the final file production if the step succeeds.

CAVEATS

When running steps in parallel, it is important to ensure that you do not call the $step->pre_commit_file method outside of the $step->run method. If you call this at object creation time, this can cause the tempdir containing the pre_commit_file file to be created and destroyed before the run method ever gets a chance to run.

SUPPORT

Bugs may be submitted through https://github.com/maxmind/Stepford/issues.

AUTHOR

Dave Rolsky <drolsky@maxmind.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 - 2023 by MaxMind, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.