Module: Amigo::ScheduledJob::ClassMethods

Defined in:
lib/amigo/scheduled_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cron_exprObject

Returns the value of attribute cron_expr.



38
39
40
# File 'lib/amigo/scheduled_job.rb', line 38

def cron_expr
  @cron_expr
end

#splay_durationObject

Returns the value of attribute splay_duration.



38
39
40
# File 'lib/amigo/scheduled_job.rb', line 38

def splay_duration
  @splay_duration
end

Instance Method Details

#cron(expr) ⇒ Object



62
63
64
# File 'lib/amigo/scheduled_job.rb', line 62

def cron(expr)
  self.cron_expr = expr
end

#event_job?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/amigo/scheduled_job.rb', line 44

def event_job?
  return false
end

#scheduled_job?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/amigo/scheduled_job.rb', line 40

def scheduled_job?
  return true
end

#splay(duration) ⇒ Object

When the cron job is run, it is re-enqueued again with a random offset. This splay prevents the ‘thundering herd’ problem, where, say, may jobs are meant to happen at minute 0. Instead, jobs are offset.

Use nil to turn off this behavior and get more precise execution. This is mostly useful for jobs that must run very often.

duration must respond to to_i.

Parameters:

  • duration (Integer, #to_i)


76
77
78
# File 'lib/amigo/scheduled_job.rb', line 76

def splay(duration)
  self.splay_duration = duration
end

#utc_hour(hour, tzstr) ⇒ Object

Return the UTC hour for the given hour and timezone. For example, during DST, ‘utc_hour(6, ’US/Pacific’)‘ returns 13 (or, 6 + 7), while in standard time (not DST) it returns 8 (or, 6 + 8). This is useful in crontab notation, when we want something to happen at a certain local time and don’t want it to shift with DST.



53
54
55
56
57
58
59
60
# File 'lib/amigo/scheduled_job.rb', line 53

def utc_hour(hour, tzstr)
  local = TZInfo::Timezone.get(tzstr)
  utc = TZInfo::Timezone.get("UTC")
  n = Time.now
  intz = Time.new(n.year, n.month, n.day, hour, n.min, n.sec, local)
  inutc = utc.to_local(intz)
  return inutc.hour
end