Class: Vidibus::WatchFolder::Job
- Inherits:
-
Struct
- Object
- Struct
- Vidibus::WatchFolder::Job
- Defined in:
- lib/vidibus/watch_folder/job.rb
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#event ⇒ Object
Returns the value of attribute event.
-
#path ⇒ Object
Returns the value of attribute path.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum
5 6 7 |
# File 'lib/vidibus/watch_folder/job.rb', line 5 def checksum @checksum end |
#delay ⇒ Object
Returns the value of attribute delay
5 6 7 |
# File 'lib/vidibus/watch_folder/job.rb', line 5 def delay @delay end |
#event ⇒ Object
Returns the value of attribute event
5 6 7 |
# File 'lib/vidibus/watch_folder/job.rb', line 5 def event @event end |
#path ⇒ Object
Returns the value of attribute path
5 6 7 |
# File 'lib/vidibus/watch_folder/job.rb', line 5 def path @path end |
#uuid ⇒ Object
Returns the value of attribute uuid
5 6 7 |
# File 'lib/vidibus/watch_folder/job.rb', line 5 def uuid @uuid end |
Class Method Details
.create(*args) ⇒ Object
29 30 31 |
# File 'lib/vidibus/watch_folder/job.rb', line 29 def create(*args) new(*args).enqueue! end |
.delete_all(uuid, event, path) ⇒ Object
33 34 35 36 |
# File 'lib/vidibus/watch_folder/job.rb', line 33 def delete_all(uuid, event, path) regex = /Vidibus::WatchFolder::Job\s*\nuuid: #{uuid}\nevent: #{event}\npath: #{path}\n/ Delayed::Backend::Mongoid::Job.delete_all(:handler => regex) end |
Instance Method Details
#enqueue! ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/vidibus/watch_folder/job.rb', line 6 def enqueue! validate! args = [self] i = delay.to_i if i > 0 args << {:run_at => Time.now+i} end Delayed::Job.enqueue(*args).id end |
#perform ⇒ Object
16 17 18 19 20 21 |
# File 'lib/vidibus/watch_folder/job.rb', line 16 def perform begin watch_folder.handle(event, path, checksum) rescue Mongoid::Errors::DocumentNotFound end end |
#validate! ⇒ Object
23 24 25 26 |
# File 'lib/vidibus/watch_folder/job.rb', line 23 def validate! return if uuid && event && path && checksum raise ArgumentError, 'Provide UUID, event, path, checksum, and an optional delay' end |