Class: Convertr::Convertor

Inherits:
Object
  • Object
show all
Defined in:
lib/convertr/convertor.rb

Constant Summary collapse

CONVERTOR_STOPFILE =
'stop.convertr'
CONVERTOR_PAUSEFILE =
'pause.convertr'
CONVERTOR_PAUSE_DELAY =
120
CONVERTOR_MAX_FETCH_TIME =
600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_tasks = 0, scheduler = nil) ⇒ Convertor

инициализация конертера {{{



26
27
28
29
30
31
32
33
34
# File 'lib/convertr/convertor.rb', line 26

def initialize(max_tasks = 0, scheduler = nil) # инициализация конертера {{{
  @max_tasks = max_tasks
  @logger = Logger.new($stderr)
  @initial_dir = Dir.pwd
  @scheduler = Convertr::SchedulerFactory.create(scheduler)
  @hostname = `hostname`.chomp
  @conf = Convertr::Config.instance
  @tasks = 0
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def file
  @file
end

#hostnameObject

Returns the value of attribute hostname.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def hostname
  @hostname
end

#initial_dirObject

Returns the value of attribute initial_dir.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def initial_dir
  @initial_dir
end

#loggerObject

Returns the value of attribute logger.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def logger
  @logger
end

#max_tasksObject

Returns the value of attribute max_tasks.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def max_tasks
  @max_tasks
end

#schedulerObject

Returns the value of attribute scheduler.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def scheduler
  @scheduler
end

#taskObject

Returns the value of attribute task.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def task
  @task
end

#tasksObject

Returns the value of attribute tasks.



24
25
26
# File 'lib/convertr/convertor.rb', line 24

def tasks
  @tasks
end

Instance Method Details

#runObject

}}}



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/convertr/convertor.rb', line 36

def run # запуск конвертора {{{
  loop do
    break if File.exists? CONVERTOR_STOPFILE
    if !File.exists?(CONVERTOR_PAUSEFILE) and @task = @scheduler.schedule_next_task(@hostname)
      @task.update_attributes(
        :convert_status => process_task,
        :convert_stopped_at => Time.now
      )
      break if @max_tasks > 0 && (@tasks += 1) >= @max_tasks
    else
      sleep(CONVERTOR_PAUSE_DELAY) && next
    end
  end
end