daengine 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -123,13 +123,20 @@ class DigitalAsset
123
123
  TaxonomyTerm.label_for_term(content_organization_ids[0])
124
124
  end
125
125
  def content_type
126
- type_id = documents.detect{|d| d.content_type != '549'}.try(:content_type)
126
+ type_id = first_non_finra.try(:content_type)
127
127
  TaxonomyTerm.label_for_term(type_id)
128
128
  end
129
+ def pages; first_non_finra.pages end
130
+
129
131
  def audience
130
132
  TaxonomyTerm.label_for_term(audiences[0])
131
133
  end
132
134
 
135
+ private
136
+
137
+ def first_non_finra; documents.detect{|d| d.content_type != '549'} end
138
+
139
+
133
140
  end
134
141
 
135
142
  class DigitalAsset::Document
@@ -3,78 +3,54 @@ module Daengine
3
3
 
4
4
  @@last_read_time = 2.days.ago
5
5
 
6
- def self.trap_signals
7
- sigtrap = proc {
8
- puts "DigitalAssetProcessor: caught trapped signal, shutting down"
9
- @@run = false
10
- }
11
- signals = ["SIGTERM", "SIGINT"]
12
- signals.push("SIGHUP") unless is_windows?
13
- signals.each do |signal|
14
- trap signal, sigtrap
15
- end
16
- end
17
-
18
- def self.is_windows?
19
- processor, platform, *rest = RUBY_PLATFORM.split("-")
20
- platform =~ /mswin/ || platform =~ /mingw/
21
- end
22
-
23
- def self.execute
24
- @@run = true
25
- trap_signals
26
- @@wthread = Thread.new { worker() }
27
- return @@wthread
28
- end
29
-
30
- def self.worker
31
- puts "DigitalAssetProcessor: start processing digital assets!"
32
- while @@run
33
- begin
34
- self.process_tuple_directory
35
- process_tuple_directory
36
- rescue => e
37
- puts e.message
38
- puts e.backtrace
39
- end
40
- sleep(5)
41
- end
42
- @@wthread.exit
43
- end
44
-
45
6
  def self.process_tuple_directory
46
7
  path = Daengine.config[:assets_path]
47
8
  raise "ERROR: DigitalAssetProcessor: Invalid assets_path provided. Unable to read from #{path}" unless File::directory?(path)
48
- # read the given directory, process each file in date order starting 2 days ago if last_read_time is nil
49
- time = self.read_last_process_time
50
- last_run_time = 10.years.ago
51
- if not time.blank?
52
- @@last_read_time = time
53
- last_run_time = time
54
- end
55
- Daengine.log("DigitalAssetProcessor: Last process time was #{@@last_read_time}", "info")
56
- deploy_files= []
9
+ # ensure only one instance running at a time
10
+ lockfile_name = Daengine.config[:daengine_yml_file] + '.lck'
11
+ begin
12
+ lockfile = File.new(lockfile_name, File::CREAT|File::EXCL)
57
13
 
58
- deploy_files = Dir.entries(path).select {
59
- |f| File.file?("#{path}/#{f}") and File.mtime("#{path}/#{f}") > @@last_read_time
60
- }.sort_by { |f| File.mtime("#{path}/#{f}") }
14
+ # read the given directory, process each file in date order starting 2 days ago if last_read_time is nil
15
+ time = self.read_last_process_time
16
+ last_run_time = 10.years.ago
17
+ if not time.blank?
18
+ @@last_read_time = time
19
+ last_run_time = time
20
+ end
21
+ Daengine.log("DigitalAssetProcessor: Last process time was #{@@last_read_time}", "info")
22
+ deploy_files= []
23
+
24
+ deploy_files = Dir.entries(path).select {
25
+ |f| File.file?("#{path}/#{f}") and File.mtime("#{path}/#{f}") > @@last_read_time
26
+ }.sort_by { |f| File.mtime("#{path}/#{f}") }
27
+
28
+ if deploy_files.empty?
29
+ Daengine.log("WARN: DigitalAssetProcessor: No digital asset deployment files found to process under #{path}", "warn")
30
+ else
31
+ Daengine.log("DigitalAssetProcessor: Reading digital asset deployment files from #{path}", "info")
32
+ deploy_files.each do |filename|
33
+ #parse the file and add metadata content to database.
34
+ file = File.expand_path(filename, path)
35
+ Daengine.log("DigitalAssetProcessor: Processing file #{filename} --- #{File.mtime(file)}", "info")
36
+ open_file = File.open(file, 'rb')
37
+ Daengine::TeamsiteMetadataParser.parse_tuple_file(open_file, last_run_time)
38
+ Daengine.log("DigitalAssetProcessor: Finished processing #{filename}", "info")
39
+ @@last_read_time = File.mtime(file) + 1.second
40
+ self.save_last_read_time
41
+ Daengine.log("DigitalAssetProcessor: Last process time set to #{@@last_read_time}", "info")
42
+ end
43
+ end
61
44
 
62
- if deploy_files.empty?
63
- Daengine.log("WARN: DigitalAssetProcessor: No digital asset deployment files found to process under #{path}", "warn")
64
- else
65
- Daengine.log("DigitalAssetProcessor: Reading digital asset deployment files from #{path}", "info")
66
- deploy_files.each do |filename|
67
- #parse the file and add metadata content to database.
68
- file = File.expand_path(filename, path)
69
- Daengine.log("DigitalAssetProcessor: Processing file #{filename} --- #{File.mtime(file)}", "info")
70
- open_file = File.open(file, 'rb')
71
- Daengine::TeamsiteMetadataParser.parse_tuple_file(open_file, last_run_time)
72
- Daengine.log("DigitalAssetProcessor: Finished processing #{filename}", "info")
73
- @@last_read_time = File.mtime(file) + 1.second
74
- self.save_last_read_time
75
- Daengine.log("DigitalAssetProcessor: Last process time set to #{@@last_read_time}", "info")
45
+ rescue Errno::EEXIST
46
+ Daengine.log("DigitalAssetProcessor: Already in progress. Lockfile exists at #{lockfile_name}. Aborting!", "error")
47
+ ensure
48
+ unless lockfile.nil?
49
+ lockfile.close()
50
+ File.delete(lockfile_name)
76
51
  end
77
52
  end
53
+
78
54
  end
79
55
 
80
56
  def self.save_last_read_time
@@ -90,7 +66,7 @@ module Daengine
90
66
  end
91
67
 
92
68
  def self.read_last_process_time
93
- time = 1.year.ago
69
+ time = 2.days.ago
94
70
  begin
95
71
  target = Daengine.config[:daengine_yml_file]
96
72
  property = YAML.load_file(target)
@@ -125,28 +125,34 @@ module Daengine::TeamsiteMetadataParser
125
125
  def self.trim_package(asset_docs, last_read = nil)
126
126
  docs = []
127
127
  path = Daengine.config[:digital_assets_file_directory]
128
- asset_docs.each do |doc|
129
- #exclude manifest_file
130
- unless doc['path'].match('\/manifest\/')
131
- file = File.join(path, doc['path'])
132
- #exclude digital_asset_files that are not in *Teamsite Staging*
133
- if File.exist?(file)
134
- docs << doc
135
- if(File.mtime(file) > last_read)
136
- begin
137
- exifdata = ::MiniExiftool.new("'#{file}'") # spaces in filename
138
- doc['pages'] = exifdata.pagecount # or exifdata['Slides']
139
- doc['size'] = exifdata.filesize
140
- doc['mime_type'] = exifdata.mimetype
141
- rescue Exception => e
142
- Daengine.log "Error reading metadata from #{file} #{e.message}", "error"
128
+ if Dir.exist?(path) # dont throw away assets if we can't locate the dir
129
+ asset_docs.each do |doc|
130
+ #exclude manifest_file
131
+ unless doc['path'].match('\/manifest\/')
132
+ file = File.join(path, doc['path'])
133
+ #exclude digital_asset_files that are not in *Teamsite Staging*
134
+ if File.exist?(file)
135
+ docs << doc
136
+ if(File.mtime(file) > last_read)
137
+ begin
138
+ exifdata = ::MiniExiftool.new("#{file}") # spaces in filename
139
+ doc['pages'] = exifdata.pagecount # or exifdata['Slides']
140
+ doc['size'] = exifdata.filesize
141
+ doc['mime_type'] = exifdata.mimetype
142
+ rescue Exception => e
143
+ Daengine.log "Error reading metadata from #{file} #{e.message}", "error"
144
+ end
143
145
  end
146
+ else
147
+ # the file was missing on disk, show a warning!
148
+ Daengine.log("TeamsiteMetadataParser: Unable to locate file #{file} on disk! Removing from metadata", "warn")
144
149
  end
145
- else
146
- # the file was missing on disk, show a warning!
147
- Daengine.log("TeamsiteMetadataParser: Unable to locate file #{file} on disk! Removing from metadata", "warn")
148
150
  end
149
151
  end
152
+ else
153
+ Daengine.log("******************", "error")
154
+ Daengine.log("ERROR!!! Unable to locate physical teamsite files at #{path}", "error")
155
+ Daengine.log("******************", "error")
150
156
  end
151
157
  docs
152
158
  end
@@ -1,3 +1,3 @@
1
1
  module Daengine
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -24295,3 +24295,103 @@ Completed 200 OK in 5ms (Views: 3.0ms)
24295
24295
  Processing by DigitalAssetsController#search as HTML
24296
24296
  Parameters: {"guid"=>"blargh-blargh-blargh", "title"=>"Doc Title"}
24297
24297
  Completed 200 OK in 20ms (Views: 14.0ms)
24298
+ Processing by DigitalAssetsController#index as HTML
24299
+ Rendered c:/dev/rails/daengine/app/views/digital_assets/index.html.erb within layouts/application (17.0ms)
24300
+ Completed 200 OK in 97ms (Views: 94.0ms)
24301
+ Processing by DigitalAssetsController#show as HTML
24302
+ Parameters: {"id"=>"guid-foobar-permanent-2"}
24303
+ Completed 200 OK in 37ms (Views: 6.0ms)
24304
+ Processing by DigitalAssetsController#show as HTML
24305
+ Parameters: {"id"=>"IL1111.077"}
24306
+ Completed 200 OK in 19ms (Views: 4.0ms)
24307
+ Processing by DigitalAssetsController#show as HTML
24308
+ Parameters: {"id"=>"IL1111.077"}
24309
+ Completed 200 OK in 19ms (Views: 3.0ms)
24310
+ Processing by DigitalAssetsController#show as HTML
24311
+ Parameters: {"id"=>"guid-foobar-permanent-6"}
24312
+ Completed 200 OK in 19ms (Views: 5.0ms)
24313
+ Processing by DigitalAssetsController#search as HTML
24314
+ Completed 200 OK in 8ms (Views: 7.0ms)
24315
+ Processing by DigitalAssetsController#search as HTML
24316
+ Parameters: {"path"=>"/one/off.path"}
24317
+ Completed 200 OK in 6ms (Views: 4.0ms)
24318
+ Processing by DigitalAssetsController#search as HTML
24319
+ Parameters: {"doctype"=>"666"}
24320
+ Completed 200 OK in 8ms (Views: 4.0ms)
24321
+ Processing by DigitalAssetsController#search as HTML
24322
+ Parameters: {"doctype"=>["666", "777"]}
24323
+ Completed 200 OK in 9ms (Views: 8.0ms)
24324
+ Processing by DigitalAssetsController#search as HTML
24325
+ Parameters: {"sami"=>"SOMETHING.001"}
24326
+ Completed 200 OK in 18ms (Views: 17.0ms)
24327
+ Processing by DigitalAssetsController#search as HTML
24328
+ Parameters: {"audience"=>"492"}
24329
+ Completed 200 OK in 4ms (Views: 3.0ms)
24330
+ Processing by DigitalAssetsController#search as HTML
24331
+ Parameters: {"title"=>"Doc Title"}
24332
+ Completed 200 OK in 6ms (Views: 3.0ms)
24333
+ Processing by DigitalAssetsController#search as HTML
24334
+ Parameters: {"guid"=>"guid-foobar-permanent-28"}
24335
+ Completed 200 OK in 6ms (Views: 5.0ms)
24336
+ Processing by DigitalAssetsController#search as HTML
24337
+ Parameters: {"business_owner"=>"biz owner"}
24338
+ Completed 200 OK in 7ms (Views: 3.0ms)
24339
+ Processing by DigitalAssetsController#search as HTML
24340
+ Parameters: {"guid"=>"guid-foobar-permanent-35", "title"=>"Doc Title"}
24341
+ Completed 200 OK in 7ms (Views: 6.0ms)
24342
+ Processing by DigitalAssetsController#search as HTML
24343
+ Parameters: {"title"=>"Doc Title", "audiences"=>["490"], "sami"=>"IL1111.077"}
24344
+ Completed 200 OK in 5ms (Views: 3.0ms)
24345
+ Processing by DigitalAssetsController#search as HTML
24346
+ Parameters: {"guid"=>"blargh-blargh-blargh", "title"=>"Doc Title"}
24347
+ Completed 200 OK in 20ms (Views: 14.0ms)
24348
+ Processing by DigitalAssetsController#index as HTML
24349
+ Rendered c:/dev/rails/daengine/app/views/digital_assets/index.html.erb within layouts/application (17.0ms)
24350
+ Completed 200 OK in 94ms (Views: 90.0ms)
24351
+ Processing by DigitalAssetsController#show as HTML
24352
+ Parameters: {"id"=>"guid-foobar-permanent-2"}
24353
+ Completed 200 OK in 20ms (Views: 6.0ms)
24354
+ Processing by DigitalAssetsController#show as HTML
24355
+ Parameters: {"id"=>"IL1111.077"}
24356
+ Completed 200 OK in 19ms (Views: 4.0ms)
24357
+ Processing by DigitalAssetsController#show as HTML
24358
+ Parameters: {"id"=>"IL1111.077"}
24359
+ Completed 200 OK in 21ms (Views: 3.0ms)
24360
+ Processing by DigitalAssetsController#show as HTML
24361
+ Parameters: {"id"=>"guid-foobar-permanent-6"}
24362
+ Completed 200 OK in 18ms (Views: 5.0ms)
24363
+ Processing by DigitalAssetsController#search as HTML
24364
+ Completed 200 OK in 10ms (Views: 9.0ms)
24365
+ Processing by DigitalAssetsController#search as HTML
24366
+ Parameters: {"path"=>"/one/off.path"}
24367
+ Completed 200 OK in 5ms (Views: 3.0ms)
24368
+ Processing by DigitalAssetsController#search as HTML
24369
+ Parameters: {"doctype"=>"666"}
24370
+ Completed 200 OK in 8ms (Views: 3.0ms)
24371
+ Processing by DigitalAssetsController#search as HTML
24372
+ Parameters: {"doctype"=>["666", "777"]}
24373
+ Completed 200 OK in 10ms (Views: 9.0ms)
24374
+ Processing by DigitalAssetsController#search as HTML
24375
+ Parameters: {"sami"=>"SOMETHING.001"}
24376
+ Completed 200 OK in 18ms (Views: 17.0ms)
24377
+ Processing by DigitalAssetsController#search as HTML
24378
+ Parameters: {"audience"=>"492"}
24379
+ Completed 200 OK in 4ms (Views: 3.0ms)
24380
+ Processing by DigitalAssetsController#search as HTML
24381
+ Parameters: {"title"=>"Doc Title"}
24382
+ Completed 200 OK in 6ms (Views: 3.0ms)
24383
+ Processing by DigitalAssetsController#search as HTML
24384
+ Parameters: {"guid"=>"guid-foobar-permanent-28"}
24385
+ Completed 200 OK in 6ms (Views: 5.0ms)
24386
+ Processing by DigitalAssetsController#search as HTML
24387
+ Parameters: {"business_owner"=>"biz owner"}
24388
+ Completed 200 OK in 7ms (Views: 3.0ms)
24389
+ Processing by DigitalAssetsController#search as HTML
24390
+ Parameters: {"guid"=>"guid-foobar-permanent-35", "title"=>"Doc Title"}
24391
+ Completed 200 OK in 8ms (Views: 6.0ms)
24392
+ Processing by DigitalAssetsController#search as HTML
24393
+ Parameters: {"title"=>"Doc Title", "audiences"=>["490"], "sami"=>"IL1111.077"}
24394
+ Completed 200 OK in 4ms (Views: 3.0ms)
24395
+ Processing by DigitalAssetsController#search as HTML
24396
+ Parameters: {"guid"=>"blargh-blargh-blargh", "title"=>"Doc Title"}
24397
+ Completed 200 OK in 21ms (Views: 14.0ms)
@@ -1 +1 @@
1
- last_read_time: 2010-08-27 13:27:49 -0600
1
+ last_read_time: 2012-08-28 11:03:30 -0600
@@ -1 +1 @@
1
- last_read_time: 2010-08-27 11:44:32 -0600
1
+ last_read_time: 2012-08-28 11:03:30 -0600
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: daengine
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - sbhatia
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-27 00:00:00.000000000Z
13
+ date: 2012-08-31 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails