bjornno-ruby-batch 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +16 -9
- data/lib/ruby-batch.rb +58 -32
- data/ruby-batch.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,18 +1,26 @@
|
|
1
1
|
= ruby-batch
|
2
2
|
|
3
|
-
|
3
|
+
http://github.com/bjornno/ruby-batch/
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
|
-
|
7
|
-
FIX (describe your package)
|
6
|
+
Simple DSL for batch processing
|
8
7
|
|
9
8
|
== FEATURES/PROBLEMS:
|
10
|
-
|
11
|
-
|
9
|
+
Not very useful yet
|
10
|
+
Not multithreaded
|
12
11
|
|
13
12
|
== SYNOPSIS:
|
14
13
|
|
15
|
-
|
14
|
+
require 'ruby-batch'
|
15
|
+
|
16
|
+
filescan '/data/from_host/', 'processfiles*' do |file|
|
17
|
+
# process files matching pattern from a catalog, put processing logic here.
|
18
|
+
end
|
19
|
+
|
20
|
+
dbscan db, 'process_queue' do |work_item|
|
21
|
+
# # Scans for work_items from database, put process logic here.
|
22
|
+
end
|
23
|
+
|
16
24
|
|
17
25
|
== REQUIREMENTS:
|
18
26
|
|
@@ -20,13 +28,12 @@ FIX (describe your package)
|
|
20
28
|
|
21
29
|
== INSTALL:
|
22
30
|
|
23
|
-
|
31
|
+
sudo gem install bjornno-ruby-batch
|
24
32
|
|
25
33
|
== LICENSE:
|
26
34
|
|
27
|
-
(The MIT License)
|
28
35
|
|
29
|
-
Copyright (c) 2008
|
36
|
+
Copyright (c) 2008 Bjørn Nordlund
|
30
37
|
|
31
38
|
Permission is hereby granted, free of charge, to any person obtaining
|
32
39
|
a copy of this software and associated documentation files (the
|
data/lib/ruby-batch.rb
CHANGED
@@ -3,7 +3,7 @@ require 'sequel'
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'ftools'
|
5
5
|
|
6
|
-
module
|
6
|
+
module BatchFile
|
7
7
|
|
8
8
|
def moveFile(fromfilename, fromdir, tofilename, todir)
|
9
9
|
|
@@ -27,46 +27,72 @@ module Filescanner
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def filescan(path, regexp, &block)
|
30
|
-
|
31
|
-
|
30
|
+
puts 'starting file pump'
|
31
|
+
Thread.new do
|
32
|
+
if !File.exist? path
|
33
|
+
FileUtils.mkdir_p(path)
|
34
|
+
end
|
35
|
+
while true
|
36
|
+
Dir.foreach(path) do |filename|
|
37
|
+
if (File.fnmatch(regexp, filename)) #File.directory?(file) &&
|
38
|
+
file = startProcess(path,filename)
|
39
|
+
if file != nil
|
40
|
+
#DB.transaction do
|
41
|
+
yield block [file]
|
42
|
+
#end
|
43
|
+
file.close
|
44
|
+
end
|
45
|
+
endProcess(path, filename)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
sleep 5
|
49
|
+
end
|
32
50
|
end
|
33
|
-
while true
|
34
|
-
Dir.foreach(path) do |filename|
|
35
|
-
if (File.fnmatch(regexp, filename)) #File.directory?(file) &&
|
36
|
-
file = startProcess(path,filename)
|
37
|
-
if file != nil
|
38
|
-
#DB.transaction do
|
39
|
-
yield block [file]
|
40
|
-
#end
|
41
|
-
file.close
|
42
|
-
end
|
43
|
-
endProcess(path, filename)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
sleep 5
|
47
|
-
end
|
48
51
|
end
|
49
|
-
|
52
|
+
|
53
|
+
def writefile(filepath, filename, content)
|
54
|
+
if !File.exist? filepath+'/tmp/'
|
55
|
+
FileUtils.mkdir_p(filepath+'/tmp/')
|
56
|
+
end
|
57
|
+
File.open(filepath+'/tmp/'+filename, 'w') {|f| f.write(content) }
|
58
|
+
moveFile(filename, filepath+'/tmp/', filename, filepath+'/tmp/')
|
59
|
+
end
|
60
|
+
|
50
61
|
end
|
51
62
|
|
52
|
-
module
|
63
|
+
module BatchDatabase
|
64
|
+
def createDb(db)
|
65
|
+
db << "CREATE TABLE work_item (id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, work_id INTEGER UNSIGNED NOT NULL, processing_state INTEGER UNSIGNED NOT NULL, work_queue_id INTEGER UNSIGNED NOT NULL,PRIMARY KEY(id))"
|
66
|
+
end
|
67
|
+
|
68
|
+
|
53
69
|
def dbscan(db, queue, &block)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
puts 'starting db pump'
|
71
|
+
Thread.new do
|
72
|
+
loop do
|
73
|
+
db.transaction do
|
74
|
+
workset = db[:work_item].where(:processing_state => 0).where(:work_queue_id => queue)
|
75
|
+
work = workset.first
|
76
|
+
if work != nil
|
77
|
+
yield block [work]
|
78
|
+
workset.filter(:id => work[:id]).update(:processing_state => 3)
|
79
|
+
else
|
80
|
+
sleep 10
|
81
|
+
end
|
61
82
|
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def dbpost(db, queue, work_id)
|
88
|
+
dataset = db[:work_item]
|
89
|
+
dataset.insert(:processing_state => 0, :work_queue_id => queue, :work_id => work_id)
|
65
90
|
end
|
91
|
+
|
66
92
|
end
|
67
93
|
|
68
|
-
include
|
69
|
-
include
|
94
|
+
include BatchFile
|
95
|
+
include BatchDatabase
|
70
96
|
|
71
97
|
|
72
98
|
|
data/ruby-batch.gemspec
CHANGED
@@ -3,13 +3,13 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'ruby-batch'
|
6
|
-
s.version = '0.1.
|
6
|
+
s.version = '0.1.2'
|
7
7
|
s.date = "2008-11-23"
|
8
8
|
|
9
9
|
s.description = "Simple batch frameork DSL"
|
10
10
|
s.summary = "Simple batch frameork DSL"
|
11
11
|
|
12
|
-
s.authors = ["
|
12
|
+
s.authors = ["Bjørn Nordlund"]
|
13
13
|
|
14
14
|
# = MANIFEST =
|
15
15
|
s.files = %w[
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bjornno-ruby-batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- "Bj\
|
7
|
+
- "Bj\xC3\xB8rn Nordlund"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|