Class: OpenWFE::CronJob

Inherits:
Job
  • Object
show all
Defined in:
lib/openwfe/util/scheduler.rb

Overview

A cron job.

Instance Attribute Summary collapse

Attributes inherited from Job

#block, #job_id, #params, #scheduler, #tags

Instance Method Summary collapse

Methods inherited from Job

#has_tag?, #unschedule

Constructor Details

#initialize(scheduler, cron_id, line, params, &block) ⇒ CronJob

Returns a new instance of CronJob.



1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
# File 'lib/openwfe/util/scheduler.rb', line 1025

def initialize (scheduler, cron_id, line, params, &block)

    super(scheduler, cron_id, params, &block)

    if line.is_a?(String)

        @cron_line = CronLine.new(line)

    elsif line.is_a?(CronLine)

        @cron_line = line

    else

        raise \
            "Cannot initialize a CronJob " +
            "with a param of class #{line.class}"
    end
end

Instance Attribute Details

#cron_lineObject

The CronLine instance representing the times at which the cron job has to be triggered.



1023
1024
1025
# File 'lib/openwfe/util/scheduler.rb', line 1023

def cron_line
  @cron_line
end

Instance Method Details

#matches?(time) ⇒ Boolean

This is the method called by the scheduler to determine if it has to fire this CronJob instance.

Returns:

  • (Boolean)


1049
1050
1051
1052
# File 'lib/openwfe/util/scheduler.rb', line 1049

def matches? (time)

    @cron_line.matches? time
end

#schedule_infoObject

Returns the original cron tab string used to schedule this Job. Like for example “60/3 * * * Sun”.



1066
1067
1068
1069
# File 'lib/openwfe/util/scheduler.rb', line 1066

def schedule_info

    @cron_line.original
end

#triggerObject

As the name implies.



1057
1058
1059
1060
# File 'lib/openwfe/util/scheduler.rb', line 1057

def trigger

    @block.call @job_id, @cron_line
end