Class: Vidibus::WatchFolder::Job

Inherits:
Struct
  • Object
show all
Defined in:
lib/vidibus/watch_folder/job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum

Returns:

  • (Object)

    the current value of checksum



5
6
7
# File 'lib/vidibus/watch_folder/job.rb', line 5

def checksum
  @checksum
end

#delayObject

Returns the value of attribute delay

Returns:

  • (Object)

    the current value of delay



5
6
7
# File 'lib/vidibus/watch_folder/job.rb', line 5

def delay
  @delay
end

#eventObject

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



5
6
7
# File 'lib/vidibus/watch_folder/job.rb', line 5

def event
  @event
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



5
6
7
# File 'lib/vidibus/watch_folder/job.rb', line 5

def path
  @path
end

#uuidObject

Returns the value of attribute uuid

Returns:

  • (Object)

    the current value of 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

#performObject



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

Raises:

  • (ArgumentError)


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