Sha256: 86bb4637f51003b68d9709176707a06445c5cb31310819479075e27560b1339f

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

module ActiveJob
  module Cron
    module Schedulable
      attr_reader :last_occurrence

      def ready_to_perform?(time)
        next_occurrence = schedule.next_occurrence(time).to_i
        # See IceCube's document about how #next_occurrence works
        if next_occurrence != last_occurrence
          @last_occurrence = next_occurrence
          true
        else
          false
        end
      end

      def schedule
        @schedule ||= IceCube::Schedule.new
      end

      def recurrence
        yield
      end

      def method_missing(meth, *args, &block)
        if IceCube::Rule.respond_to?(meth)
          rule = IceCube::Rule.send(meth, *args, &block)
          schedule.add_recurrence_rule(rule)
          rule
        elsif schedule.respond_to?(meth)
          schedule.send(meth, *args, &block)
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_job-cron-0.1.0 lib/active_job/cron/schedulable.rb