Class: Job
- Inherits:
-
Object
- Object
- Job
- Defined in:
- lib/job.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#cron ⇒ Object
Returns the value of attribute cron.
-
#last_executed ⇒ Object
Returns the value of attribute last_executed.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name, cron, block) ⇒ Job
constructor
A new instance of Job.
- #should_execute? ⇒ Boolean
Constructor Details
#initialize(name, cron, block) ⇒ Job
Returns a new instance of Job.
4 5 6 7 8 |
# File 'lib/job.rb', line 4 def initialize (name, cron, block) @name = name @cron = cron @block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
2 3 4 |
# File 'lib/job.rb', line 2 def block @block end |
#cron ⇒ Object
Returns the value of attribute cron.
2 3 4 |
# File 'lib/job.rb', line 2 def cron @cron end |
#last_executed ⇒ Object
Returns the value of attribute last_executed.
2 3 4 |
# File 'lib/job.rb', line 2 def last_executed @last_executed end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/job.rb', line 2 def name @name end |
Instance Method Details
#execute ⇒ Object
40 41 42 43 |
# File 'lib/job.rb', line 40 def execute @last_executed = Time.new @block.call end |
#should_execute? ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/job.rb', line 10 def should_execute? min, hour, day_of_month, month, day_of_week = cron.split("\s") if (day_of_week == "7") day_of_week = 0 end now = Time.now if !field_check? min, now.min return false end if !field_check? hour, now.hour return false end if !field_check? day_of_month, now.day return false end if !field_check? month, now.month return false end if !field_check? day_of_week, now.wday return false end return true; end |