lib/crono_trigger/schedulable.rb in crono_trigger-0.2.0 vs lib/crono_trigger/schedulable.rb in crono_trigger-0.3.0

- old
+ new

@@ -112,16 +112,25 @@ end def activate_schedule!(at: Time.current) time = calculate_next_execute_at || at + attributes = {} + unless self[crono_trigger_column_name(:next_execute_at)] + attributes[crono_trigger_column_name(:next_execute_at)] = time + end + + if self.class.column_names.include?(crono_trigger_column_name(:started_at)) + unless self[crono_trigger_column_name(:started_at)] + attributes[crono_trigger_column_name(:started_at)] = time + end + end + if new_record? - self[crono_trigger_column_name(:next_execute_at)] ||= time + self.attributes = attributes else - unless self[crono_trigger_column_name(:next_execute_at)] - update_column(crono_trigger_column_name(:next_execute_at), time) - end + update_columns(attributes) end end def retry! logger.info "Retry #{self.class}-#{id}" if logger @@ -183,10 +192,10 @@ end def calculate_next_execute_at(now = Time.current) if self[crono_trigger_column_name(:cron)] tz = self[crono_trigger_column_name(:timezone)].try { |zn| TZInfo::Timezone.get(zn) } - base = [now, self[crono_trigger_column_name(:started_at)]].max + base = [now, self[crono_trigger_column_name(:started_at)]].compact.max cron_now = tz ? base.in_time_zone(tz) : base Chrono::NextTime.new(now: cron_now, source: self[crono_trigger_column_name(:cron)]).to_time end end