Module: Sipity::Jobs

Defined in:
app/jobs/sipity/jobs.rb,
app/jobs/sipity/jobs/doi_creation_request_job.rb

Overview

Responsible for processing a single concept in an asynchronous manner. That means we are only passing primatives to the Jobs and it is the Jobs responsibility to reify the correct objects.

See Also:

Defined Under Namespace

Classes: DoiCreationRequestJob

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_job_by_name(job_name) ⇒ Object (private)


23
24
25
26
27
28
29
30
# File 'app/jobs/sipity/jobs.rb', line 23

def find_job_by_name(job_name)
  job_name_as_constant = job_name.to_s.classify
  if const_defined?(job_name_as_constant)
    const_get(job_name_as_constant)
  else
    fail Exceptions::JobNotFoundError, name: job_name, container: self
  end
end

.submit(job_name, *args) ⇒ Object

Herein lies the inflection point. If you want to run things asynchronously, this is your place to make changes.


17
18
19
20
21
# File 'app/jobs/sipity/jobs.rb', line 17

def submit(job_name, *args)
  job = find_job_by_name(job_name)
  verify_primativeness_of!(*args)
  job.submit(*args)
end

.verify_primativeness_of!Object (private)


33
34
35
36
37
38
# File 'app/jobs/sipity/jobs.rb', line 33

def verify_primativeness_of!(*)
  # REVIEW: Would it make sense to verify that each of the args is a
  #   primative? Given that we could be passing this information through
  #   REDIS
  true
end

Instance Method Details

#find_job_by_name(job_name) ⇒ Object (private)


23
24
25
26
27
28
29
30
# File 'app/jobs/sipity/jobs.rb', line 23

def find_job_by_name(job_name)
  job_name_as_constant = job_name.to_s.classify
  if const_defined?(job_name_as_constant)
    const_get(job_name_as_constant)
  else
    fail Exceptions::JobNotFoundError, name: job_name, container: self
  end
end

#submit(job_name, *args) ⇒ Object (private)

Herein lies the inflection point. If you want to run things asynchronously, this is your place to make changes.


17
18
19
20
21
# File 'app/jobs/sipity/jobs.rb', line 17

def submit(job_name, *args)
  job = find_job_by_name(job_name)
  verify_primativeness_of!(*args)
  job.submit(*args)
end

#verify_primativeness_of!Object (private)


33
34
35
36
37
38
# File 'app/jobs/sipity/jobs.rb', line 33

def verify_primativeness_of!(*)
  # REVIEW: Would it make sense to verify that each of the args is a
  #   primative? Given that we could be passing this information through
  #   REDIS
  true
end