lib/rocket_job/jobs/dirmon_job.rb in rocketjob-2.1.3 vs lib/rocket_job/jobs/dirmon_job.rb in rocketjob-3.0.0.alpha
- old
+ new
@@ -13,14 +13,15 @@
# * If the job implements #upload, that method is called
# and then the file is deleted, or moved to the archive_directory if supplied
# * Otherwise, the file is moved to the supplied archive_directory (defaults to
# `_archive` in the same folder as the file itself. The absolute path and
- # file name of the archived file is passed into the job as it's first argument.
+ # file name of the archived file is passed into the job as either
+ # `upload_file_name` or `full_file_name`.
# Note:
- # - Jobs that do not implement #upload _must_ have a Hash as the first argument
+ # - Jobs that do not implement #upload _must_ have either `upload_file_name` or `full_file_name` as an attribute.
#
# With RocketJob Pro, the file is automatically uploaded into the job itself
# using the job's #upload method, after which the file is archived or deleted
# if no archive_directory was specified in the DirmonEntry.
#
@@ -37,17 +38,16 @@
# Only allow one DirmonJob instance to be running at a time
include RocketJob::Plugins::Singleton
# Start a new job when this one completes, fails, or aborts
include RocketJob::Plugins::Restart
- rocket_job do |job|
- job.priority = 40
- end
+ self.priority = 40
# 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]
+ field :check_seconds, type: Float, default: 300.0
+ # Hash[file_name, size]
+ field :previous_file_names, type: Hash, default: {}
before_create :set_run_at
# Iterate over each Dirmon entry looking for new files
# If a new file is found, it is not processed immediately, instead
@@ -66,10 +66,10 @@
# Checks the directories for new files, starting jobs if files have not changed
# since the last run
def check_directories
new_file_names = {}
- DirmonEntry.where(state: :enabled).each do |entry|
+ DirmonEntry.enabled.each do |entry|
entry.each do |pathname|
# BSON Keys cannot contain periods
key = pathname.to_s.gsub('.', '_')
previous_size = previous_file_names[key]
if size = check_file(entry, pathname, previous_size)