lib/rocket_job/jobs/dirmon_job.rb in rocketjob-1.2.1 vs lib/rocket_job/jobs/dirmon_job.rb in rocketjob-1.3.0

- old
+ new

@@ -39,31 +39,33 @@ job.priority = 40 end # Number of seconds between directory scans. Default 5 mins key :check_seconds, Float, default: 300.0 + key :previous_file_names, Hash # Hash[file_name, size] # Iterate over each Dirmon entry looking for new files # If a new file is found, it is not processed immediately, instead # it is passed to the next run of this job along with the file size. # If the file size has not changed, the Job is kicked off. - def perform(previous_file_names={}) - new_file_names = check_directories(previous_file_names) + def perform + check_directories ensure # Run again in the future, even if this run fails with an exception - self.class.perform_later(new_file_names || previous_file_names) do |job| - job.priority = priority - job.check_seconds = check_seconds - job.run_at = Time.now + check_seconds - end + self.class.create!( + previous_file_names: previous_file_names, + priority: priority, + check_seconds: check_seconds, + run_at: Time.now + check_seconds + ) end protected # Checks the directories for new files, starting jobs if files have not changed # since the last run - def check_directories(previous_file_names) + def check_directories new_file_names = {} DirmonEntry.where(state: :enabled).each do |entry| entry.each do |pathname| # BSON Keys cannot contain periods key = pathname.to_s.gsub('.', '_') @@ -71,10 +73,10 @@ if (size = check_file(entry, pathname, previous_size)) new_file_names[key] = size end end end - new_file_names + self.previous_file_names = new_file_names end # Checks if a file should result in starting a job # Returns [Integer] file size, or nil if the file started a job def check_file(entry, pathname, previous_size)