Module: Arask

Defined in:
lib/arask.rb,
lib/arask/setup.rb,
lib/arask/railtie.rb,
lib/arask/version.rb,
lib/arask/run_jobs.rb,
lib/arask/arask_job.rb

Defined Under Namespace

Classes: AraskJob, InstallGenerator, Railtie, RunJobs, Setup

Constant Summary collapse

VERSION =
'1.2.6'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.exception_blockObject

Returns the value of attribute exception_block.



8
9
10
# File 'lib/arask.rb', line 8

def exception_block
  @exception_block
end

.exception_emailObject

Returns the value of attribute exception_email.



8
9
10
# File 'lib/arask.rb', line 8

def exception_email
  @exception_email
end

.exception_email_fromObject

Returns the value of attribute exception_email_from.



8
9
10
# File 'lib/arask.rb', line 8

def exception_email_from
  @exception_email_from
end

.jobs_blockObject

Returns the value of attribute jobs_block.



8
9
10
# File 'lib/arask.rb', line 8

def jobs_block
  @jobs_block
end

.jobs_touchedObject

Returns the value of attribute jobs_touched.



8
9
10
# File 'lib/arask.rb', line 8

def jobs_touched
  @jobs_touched
end

Class Method Details

.init_jobsObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/arask.rb', line 30

def self.init_jobs
  Arask.jobs_touched = []
  Arask.jobs_block.call(Setup)
  Arask.jobs_block = nil
  begin
    AraskJob.all.where.not(id: Arask.jobs_touched).delete_all
    Arask.jobs_touched = nil
    Arask.queue_self
  rescue
  end
end

.queue_selfObject



42
43
44
45
46
47
48
49
50
# File 'lib/arask.rb', line 42

def self.queue_self
  begin
    next_job_run = AraskJob.order(execute_at: :asc).first.try(:execute_at)
    # At least check database for jobs every day
    next_job_run = 1.day.from_now if next_job_run.nil? or (next_job_run - DateTime.now)/60/60 > 24
    RunJobs.set(wait_until: next_job_run).perform_later
  rescue
  end
end

.setup(force_run = false, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/arask.rb', line 10

def self.setup(force_run = false, &block)
  Arask.jobs_block = block
  if Rails::VERSION::MAJOR>=6
    # Make sure we only run setup now if we are testing.
    # Else we would run them at every cli execution.
    # railtie.rb inits the jobs when the server is ready
    Arask.init_jobs if force_run
  else # Rails is less than 6
    
    # Make sure we only run setup if Rails is actually run as a server or testing.
    return unless defined?(Rails::Server) or force_run
    # If we don't wait and rails is setup to use another language, ActiveJob
    # saves what is now (usually :en) and reloads that when trying to run the
    # job. Renderering an I18n error of unsupported language.
    ActiveSupport.on_load :after_initialize, yield: true do
      Arask.init_jobs
    end
  end
end