Class: Hippo::Job

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
Jobba::RecordStatus
Defined in:
lib/hippo/job.rb,
lib/hippo/job/failure_logger.rb

Overview

A job in hippo is identical to a ActiveJob::Base job, except it records it's status using the Jobba::Status mixin module

Defined Under Namespace

Classes: FailureLogger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Jobba::RecordStatus

included

Class Method Details

.api_status_message(job, message = "Job started") ⇒ Object


69
70
71
72
73
74
75
# File 'lib/hippo/job.rb', line 69

def self.api_status_message(job, message="Job started")
    return {
        success: true, message: message, data: {
            job: Hippo::Job.status_for_id(job.job_id)
        }
    }
end

.status_for_id(id) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hippo/job.rb', line 53

def self.status_for_id(id)
    status = Jobba.find(id)
    return nil unless status
    {
        id:          status.id,
        job_name:    status.job_name,
        progress:    status.progress,
        attempt:     status.attempt,
        state:       status.state.name,
        recorded_at: status.recorded_at,
        queued_at:   status.queued_at,
        errors:      status.errors,
        data:        status.data
    }
end

Instance Method Details

#deliver_progress_to_clientsObject


40
41
42
43
44
45
# File 'lib/hippo/job.rb', line 40

def deliver_progress_to_clients
    ::Hippo::API::PubSub.publish(
        "/hippo/job-statuses/#{job_id}",
        update: Job.status_for_id(job_id)
    )
end

#save_progress(output, progress = 1.0) ⇒ Object


47
48
49
50
51
# File 'lib/hippo/job.rb', line 47

def save_progress(output, progress=1.0)
    job_status.set_progress(progress)
    job_status.save(output: output)
    deliver_progress_to_clients
end