Class: CleanJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/clean_job.rb

Overview

This job remove Happenings and Tickets expired from an arbitrary days number. Remove old data is required to grant the user privacy

Instance Method Summary collapse

Instance Method Details

#perform(days: nil) ⇒ ARRAY, NIL

On perform, expired Happenings from an arbitrary days number are destroyed. On destroy each [Happening] destroy relative [Ticket]s

Examples:

destroy Happening expired from 60 days

CleanJob.perform_now(days: 60)

destroy anyting

CleanJob.perform_now
CleanJob.perform_now(days: nil)

Parameters:

  • days (Integer, Nil) (defaults to: nil)

    destroy Happening exired from :days

Returns:

  • (ARRAY)

    of destroyed happenings

  • (NIL)

    if :days isn’t defined, return nil and anyting is destroyed



17
18
19
# File 'app/jobs/clean_job.rb', line 17

def perform(days: nil)
  Happening.where(start_at: [ ..Time.zone.now.to_date - days.to_i ]).destroy_all if days.present?
end