Class: Blender::ScheduledJob

Inherits:
Object
  • Object
show all
Defined in:
lib/blender/scheduled_job.rb

Overview

A scheduled job encapsulates a blender based job to be executed at certain interval. Job is specified as a file path, where the file contains job written in blender’s DSL. Job interval can be specified either via cron or every method

Blender::Timer object uses ScheduledJob and to execute the job and Rufus::Scheduler to schedule it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ScheduledJob

create a new instance

Parameters:

  • name (String)

    name of the job



30
31
32
33
# File 'lib/blender/scheduled_job.rb', line 30

def initialize(name)
  @name = name
  @file = name
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



27
28
29
# File 'lib/blender/scheduled_job.rb', line 27

def file
  @file
end

#scheduleObject (readonly)

Returns the value of attribute schedule.



27
28
29
# File 'lib/blender/scheduled_job.rb', line 27

def schedule
  @schedule
end

Instance Method Details

#blender_file(file) ⇒ Object

set the path of the file holding blender job

Parameters:

  • file (String)

    path of the blender file



38
39
40
# File 'lib/blender/scheduled_job.rb', line 38

def blender_file(file)
  @file = file
end

#cron(line) ⇒ Object

set the job inteval via cron syntax. The value is passed as it is to rufus scheduler.

Parameters:

  • line (String)

    job interval in cron syntax e.g (*/5 * * * *)



46
47
48
# File 'lib/blender/scheduled_job.rb', line 46

def cron(line)
  @schedule = [ __method__, line]
end

#every(interval) ⇒ Object

set the job inteval after every specified seconds to rufus scheduler.

Parameters:

  • interval (Fixnum)

    job interval in seconds



54
55
56
# File 'lib/blender/scheduled_job.rb', line 54

def every(interval)
  @schedule = [ __method__, interval]
end

#runObject

invoke a blender run based on the blender_file



59
60
61
62
63
64
# File 'lib/blender/scheduled_job.rb', line 59

def run
  des = File.read(file)
  Blender.blend(file) do |sch|
    sch.instance_eval(des, __FILE__, __LINE__)
  end
end