-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.jl
53 lines (43 loc) · 1 KB
/
main.jl
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
using Distributed
# instantiate and precompile environment
@everywhere begin
using Pkg; Pkg.activate(@__DIR__)
Pkg.instantiate(); Pkg.precompile()
end
# load dependencies and helper functions
@everywhere begin
using ProgressMeter
using CSV
function process(infile, outfile)
# read file from disk
csv = CSV.File(infile)
# perform calculations
sleep(60)
# save new file to disk
CSV.write(outfile, csv)
end
end
# MAIN SCRIPT
# -----------
# relevant directories
indir = joinpath(@__DIR__,"data")
outdir = joinpath(@__DIR__,"results")
# files to process
infiles = readdir(indir, join=true)
outfiles = joinpath.(outdir, basename.(infiles))
nfiles = length(infiles)
# process files in parallel
status = @showprogress pmap(1:nfiles) do i
try
process(infiles[i], outfiles[i])
true # success
catch e
false # failure
end
end
# report files that failed
failed = infiles[.!status]
if !isempty(failed)
println("List of files that failed:")
foreach(println, failed)
end