A
A
Alexander Korolev2016-10-27 15:30:16
ruby
Alexander Korolev, 2016-10-27 15:30:16

How to properly design a class hierarchy for periodic tasks of various types?

Good afternoon.
It is required to create a base class, let's call it CronTask (that is, a task that will be scheduled) and then there will be many descendants that will implement their tasks, but the base class must run all active tasks.

class CronTask
  class << self
    def run_all
      descendants.select{|a| a.active?}.each{|a| a.run}
    end
  end
end

class SpecialTask << CronTask
  def self.run
    p 'special task'
  end
end

Something similar, but I don't think it's the right direction.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question