Class: Convertr::Convertor
- Inherits:
-
Object
- Object
- Convertr::Convertor
- 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
-
#file ⇒ Object
Returns the value of attribute file.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#initial_dir ⇒ Object
Returns the value of attribute initial_dir.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_tasks ⇒ Object
Returns the value of attribute max_tasks.
-
#scheduler ⇒ Object
Returns the value of attribute scheduler.
-
#task ⇒ Object
Returns the value of attribute task.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
-
#initialize(max_tasks = 0, scheduler = nil) ⇒ Convertor
constructor
инициализация конертера {{{.
-
#run ⇒ Object
}}}.
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
#file ⇒ Object
Returns the value of attribute file.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def file @file end |
#hostname ⇒ Object
Returns the value of attribute hostname.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def hostname @hostname end |
#initial_dir ⇒ Object
Returns the value of attribute initial_dir.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def initial_dir @initial_dir end |
#logger ⇒ Object
Returns the value of attribute logger.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def logger @logger end |
#max_tasks ⇒ Object
Returns the value of attribute max_tasks.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def max_tasks @max_tasks end |
#scheduler ⇒ Object
Returns the value of attribute scheduler.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def scheduler @scheduler end |
#task ⇒ Object
Returns the value of attribute task.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def task @task end |
#tasks ⇒ Object
Returns the value of attribute tasks.
24 25 26 |
# File 'lib/convertr/convertor.rb', line 24 def tasks @tasks end |
Instance Method Details
#run ⇒ Object
}}}
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 |