2019-03-26 15:32:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-16 16:44:29 +00:00
|
|
|
# Base para trabajos
|
2018-01-02 17:19:25 +00:00
|
|
|
class ApplicationJob < ActiveJob::Base
|
2023-03-28 23:21:52 +00:00
|
|
|
include Que::ActiveJob::JobExtensions
|
2020-05-30 19:43:25 +00:00
|
|
|
|
2024-03-25 16:32:08 +00:00
|
|
|
# Esperar una cantidad random de segundos primos, para que no se
|
|
|
|
# superpongan tareas
|
|
|
|
#
|
2024-03-25 16:33:52 +00:00
|
|
|
# @return [Array<Integer>]
|
|
|
|
RANDOM_WAIT = [3, 5, 7, 11, 13]
|
2024-03-25 16:32:08 +00:00
|
|
|
|
|
|
|
# @return [ActiveSupport::Duration]
|
|
|
|
def self.random_wait
|
2024-03-25 16:33:52 +00:00
|
|
|
RANDOM_WAIT.sample.seconds
|
2024-03-25 16:32:08 +00:00
|
|
|
end
|
|
|
|
|
2024-04-10 14:00:18 +00:00
|
|
|
attr_reader :site
|
|
|
|
|
2020-05-30 19:43:25 +00:00
|
|
|
private
|
|
|
|
|
2024-04-09 17:16:01 +00:00
|
|
|
# Si falla por cualquier cosa informar y descartar
|
2024-04-15 14:54:28 +00:00
|
|
|
discard_on(Exception) do |job, error|
|
|
|
|
ExceptionNotifier.notify_exception(error, data: { job: job })
|
2020-05-30 19:43:25 +00:00
|
|
|
end
|
2018-01-02 17:19:25 +00:00
|
|
|
end
|