0

I might save a schedule in db repeats = schedule.to_hash or repeats = schedule.to_yaml then use it from db schedule = repeats.from_hash

But I need to know what is a rule. For example, if it is repeated weekly, how could I store a rule in db or how could I know rule from schedule? Is it some methods like .to_hash and .from_hash for rules?

Gabi
  • 250
  • 1
  • 4
  • 13

1 Answers1

0

A Schedule can have many reoccurring and exception rules. You could get them by doing schedule.recurrence_rules or schedule.exception_rules. In addition there can be recurrence times and exception times as well. (For detailed information on what these rules are, head to: https://github.com/seejohnrun/ice_cube#quick-introductions)

Hence, it is a best practice to just store a serialized Schedule in the database and not a particular rule.

If you wish, methods like to_hash and to_yaml are available on a rule as well:

irb(main)> schedule.recurrence_rules.first.to_yaml
=> "---\n:validations: {}\n:rule_type: IceCube::DailyRule\n:interval: 1\n"

irb(main)> schedule.recurrence_rules.first.to_hash
=> {:validations=>{}, :rule_type=>"IceCube::DailyRule", :interval=>1}
pungoyal
  • 1,768
  • 15
  • 17