-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelibconnected.pl
executable file
·65 lines (52 loc) · 1.99 KB
/
relibconnected.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
#
# ReLibConectEd Software
#
# John Houser
# john.houser@multco.us
#
# This script checks for uploaded student data files in $srv_path and starts
# the ingester process. Run this script via cron job, as the libconnected
# user, every five minutes or so.
#
use strict;
use File::Find qw(find);
# File paths. Edit if you move this application or the path to search for
# data files to ingest.
my $srv_path = '/srv/libconnected';
my $base_path = '/opt/librelibconnected';
# Don't change these unless you need to.
my $config_file = "$base_path/config.yaml";
my $flag_file = "$base_path/run/ingestor.flag";
my $ingestor = "$base_path/ingestor.pl";
# Standard utilities. Check to make sure these exist.
my $touch = '/usr/bin/touch';
my $rm = '/usr/bin/rm';
###############################################################################
# Do not edit below this point
###############################################################################
# Change to the $base_path so that ILSWS.pm gets the correct working dir.
chdir $base_path;
# Check if a flag file exists, indicating that an ingest is already in progress.
if ( -e $flag_file ) {
# Found a flag file indicating an ingest is in progress, so exit without
# doing anything.
exit(1);
}
# Check incoming path for uploaded data files. Find returns all files in
# the $srv_path and passes them to the wanted subroutine as $_.
find( \&wanted, $srv_path );
sub wanted {
# Is this a CSV file in an incoming dir?
if ( $File::Find::dir =~ /incoming$/ && $_ =~ /\.csv$/ ) {
# Found a data file. Set the flag indicating an ingest is in progess.
system("$touch $flag_file") == 0
|| die "ERROR: Could not create flag file: $flag_file";
# Run the ingestor script.
system("$ingestor $config_file $File::Find::dir/$_") == 0
|| die "ERROR: $ingestor failed";
# Delete the flag file.
system("$rm $flag_file") == 0
|| die "ERROR: Could not remove $flag_file";
}
}