Sha256: ce771ec45609d233329742b50b3ef2f63a985c49767af65d0061d5e4192cc6dd

Contents?: true

Size: 823 Bytes

Versions: 23

Compression:

Stored size: 823 Bytes

Contents

module Marty
  module BackgroundJob
    class Schedule < Marty::Base
      self.table_name = 'marty_background_job_schedules'

      # Copied and adjusted:
      # https://github.com/javan/whenever/blob/e4507e2ed2158c603f0c334a8b0a957711db343a/lib/whenever/cron.rb
      REGEX = %r{\A(((\*?[\d/,\-]*)\s){3,4}(\*?([\d/,\-])*\s)(\*?([\d/,\-])*))\z}i

      validates :job_class, :cron, :state, presence: true
      validates :job_class, uniqueness: true
      validates :cron, format: { with: REGEX }

      validate :job_class_validation

      ALL_STATES = %w[on off].freeze
      enum state: ALL_STATES.zip(ALL_STATES).to_h

      def job_class_validation
        job_class.constantize.respond_to?(:schedule)
      rescue NameError
        errors.add(:job_class, "doesn't exist")
        false
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
marty-9.5.1 app/models/marty/background_job/schedule.rb
marty-9.5.0 app/models/marty/background_job/schedule.rb
marty-9.3.3 app/models/marty/background_job/schedule.rb
marty-9.3.2 app/models/marty/background_job/schedule.rb
marty-9.3.0 app/models/marty/background_job/schedule.rb
marty-8.5.0 app/models/marty/background_job/schedule.rb
marty-8.4.1 app/models/marty/background_job/schedule.rb
marty-8.3.1 app/models/marty/background_job/schedule.rb
marty-8.2.0 app/models/marty/background_job/schedule.rb
marty-8.0.0 app/models/marty/background_job/schedule.rb
marty-6.1.0 app/models/marty/background_job/schedule.rb
marty-5.2.0 app/models/marty/background_job/schedule.rb
marty-5.1.4 app/models/marty/background_job/schedule.rb
marty-5.1.3 app/models/marty/background_job/schedule.rb
marty-5.1.2 app/models/marty/background_job/schedule.rb
marty-5.1.1 app/models/marty/background_job/schedule.rb
marty-5.1.0 app/models/marty/background_job/schedule.rb
marty-3.1.0 app/models/marty/background_job/schedule.rb
marty-3.0.1 app/models/marty/background_job/schedule.rb
marty-4.0.0.rc2 app/models/marty/background_job/schedule.rb