Method: Auth::Work::Communication#enqueue_repeat

Defined in:
app/models/auth/work/communication.rb

#enqueue_repeatObject



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'app/models/auth/work/communication.rb', line 199

def enqueue_repeat
  if self.repeated_times  < self.repeat_times
    if self.repeat
      if self.decrement_repeated_times
        puts "repeated times"
        puts self.repeated_times
        puts "repeat times."
        puts self.repeat_times
      
      
        
        enqueue_repeat_at = nil
        
        case self.repeat
        when "Daily"
          enqueue_repeat_at = Time.now + 1.day
        when "Weekly"
          enqueue_repeat_at = Time.now + 1.week
        when "Monthly"
          enqueue_repeat_at = Time.now + 1.month
        when "Yearly"
          enqueue_repeat_at = Time.now + 1.year
        when "Half-Monthly"
          enqueue_repeat_at = Time.now + 6.months
        end

        args = {}
        args[:instruction_id] = self._instruction.id.to_s if self._instruction
        args[:communication_id] = self.id.to_s
        args[:cart_item_id] = self._cart_item.id.to_s  if self._cart_item
        args[:product_id] = self._product.id.to_s  if self._product
        args[:cycle_id] = self._cycle.id.to_s  if self._cycle

        CommunicationJob.set(wait_until: enqueue_repeat_at).perform_later(args)
      end
    end
  end
end