Skip to content

Instantly share code, notes, and snippets.

@HakimCassimallyBBC
Created March 6, 2017 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HakimCassimallyBBC/123c57e279dddd70a0238cce0abe990d to your computer and use it in GitHub Desktop.
Save HakimCassimallyBBC/123c57e279dddd70a0238cce0abe990d to your computer and use it in GitHub Desktop.
Sketch for processing a queue of files (several instances can be launched in parallel)
use strict;
use warnings;
use File::Spec;
my $in = 'in';
my $out = 'out';
sub process {
my ($in, $out, $callback) = @_;
opendir (my $DIR, $in) or die "Failed to open dir $in: $!";
for my $file (readdir $DIR) {
next if $file=~/^\./;
my $in_file = File::Spec->catfile($in, $file);
my $out_file = File::Spec->catfile($out, $file);
if (rename($in_file, $out_file)) {
$callback->($out_file);
}
}
}
sub write_to_s3 {
my ($xml) = @_;
print "Writing $xml to s3: ";
open (my $IN, '<', $xml) or die "Coudln't open $xml: $!";
print do {local $/; <$IN>};
print "\n";
unlink($xml);
}
while (1) {
process($in, $out, \&write_to_s3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment