Class: Webpipe::CrawlJob

Inherits:
Object
  • Object
show all
Defined in:
lib/webpipe/types.rb

Overview

Status and (partial or final) results of a crawl job. Results expire 24h after completion (see expires_at).

Constant Summary collapse

STATUS_SCRAPING =
"scraping"
STATUS_COMPLETED =
"completed"
STATUS_FAILED =
"failed"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, total: 0, completed: 0, data: [], errors: [], expires_at: nil) ⇒ CrawlJob

Returns a new instance of CrawlJob.



57
58
59
60
61
62
63
64
# File 'lib/webpipe/types.rb', line 57

def initialize(status:, total: 0, completed: 0, data: [], errors: [], expires_at: nil)
  @status = status
  @total = total
  @completed = completed
  @data = data
  @errors = errors
  @expires_at = expires_at
end

Instance Attribute Details

#completedObject (readonly)

Returns the value of attribute completed.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def completed
  @completed
end

#dataObject (readonly)

Returns the value of attribute data.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def errors
  @errors
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def expires_at
  @expires_at
end

#statusObject (readonly)

Returns the value of attribute status.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def status
  @status
end

#totalObject (readonly)

Returns the value of attribute total.



55
56
57
# File 'lib/webpipe/types.rb', line 55

def total
  @total
end

Class Method Details

.from_hash(hash) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/webpipe/types.rb', line 66

def self.from_hash(hash)
  new(
    status: hash["status"],
    total: hash["total"] || 0,
    completed: hash["completed"] || 0,
    data: (hash["data"] || []).map { |d| Document.from_hash(d) },
    errors: hash["errors"] || [],
    expires_at: hash["expires_at"]
  )
end