Skip to content

Commit

Permalink
Avoid duplicate jobs error
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Oct 5, 2016
1 parent b762add commit 3f25e0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/plugin/swissmedic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def verify_packages(file2open)

def trace_memory_useage
max_mbytes = 16 * 1024
while @@do_tracing
while $swissmedic_do_tracing
bytes = File.read("/proc/#{$$}/stat").split(' ').at(22).to_i
mbytes = bytes / (2**20)
LogFile.debug("Using #{mbytes} MB of memory. Limit is #{max_mbytes}")
Expand All @@ -170,7 +170,7 @@ def trace_memory_useage
end
sleep(1)
next if (Time.now-startTime).to_i > 60 # report time every 60 seconds,regardless of CPU useage
break unless @@do_tracing
break unless $swissmedic_do_tracing
end
end
end
Expand All @@ -187,7 +187,7 @@ def update(opts = {}, agent=Mechanize.new, target=get_latest_file(agent))
file2open = target if target and File.exists?(target)
threads = []
threads << Thread.new do
@@do_tracing = true
$swissmedic_do_tracing = true
threads.last.priority = threads.last.priority + 1
trace_memory_useage
end
Expand Down Expand Up @@ -310,9 +310,21 @@ def update(opts = {}, agent=Mechanize.new, target=get_latest_file(agent))
false
end
LogFile.debug " done. #{@export_registrations.size} export_registrations @update_comps was #{@update_comps} with #{@diff ? "#{@diff.changes.size} changes" : 'no change information'}"
@@do_tracing = false
LogFile.debug " done0. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"
$swissmedic_do_tracing = false
LogFile.debug " done1. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"
threads.map(&:join)
LogFile.debug " done2. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"

sleep(1.1)
LogFile.debug " done3. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"
threads.map(&:join)
LogFile.debug " done4. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"

@update_comps ? true : @diff
ensure
LogFile.debug " done5 ensure. $swissmedic_do_tracing is #{$swissmedic_do_tracing}. Having #{threads.size} threads"
$swissmedic_do_tracing = false
end
# check diff from overwritten stored-objects by admin
# about data-fields
Expand Down
1 change: 1 addition & 0 deletions test/test_plugin/swissmedic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def setup

@test_packages = File.expand_path '../data/xlsx/Packungen.xlsx', File.dirname(__FILE__)
latest_to = File.expand_path('../../data/xls/Packungen-latest.xlsx', File.dirname(__FILE__))
FileUtils.makedirs(File.dirname(latest_to))
FileUtils.cp(@test_packages, latest_to, :verbose => true, :preserve => true)


Expand Down

0 comments on commit 3f25e0e

Please sign in to comment.