Class: MeiliSearch::Models::Task

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/meilisearch/models/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata_hash, task_endpoint) ⇒ Task

Returns a new instance of Task.



15
16
17
18
19
20
# File 'lib/meilisearch/models/task.rb', line 15

def initialize(, task_endpoint)
  self. = 
  validate_required_fields! 

  @task_endpoint = task_endpoint
end

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata.



13
14
15
# File 'lib/meilisearch/models/task.rb', line 13

def 
  @metadata
end

Instance Method Details

#await(timeout_in_ms = 5000, interval_in_ms = 50) ⇒ Object



99
100
101
102
103
# File 'lib/meilisearch/models/task.rb', line 99

def await(timeout_in_ms = 5000, interval_in_ms = 50)
  refresh with: @task_endpoint.wait_for_task(uid, timeout_in_ms, interval_in_ms) unless finished?

  self
end

#cancelObject



105
106
107
108
109
110
111
112
# File 'lib/meilisearch/models/task.rb', line 105

def cancel
  return true if status_cancelled?
  return false if status_finished?

  @task_endpoint.cancel_tasks(uids: [uid]).await

  cancelled?
end

#cancelled?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/meilisearch/models/task.rb', line 71

def cancelled?
  Utils.warn_on_unfinished_task(self) if unfinished?

  status_cancelled?
end

#deleteObject



114
115
116
117
118
119
120
# File 'lib/meilisearch/models/task.rb', line 114

def delete
  return false unless status_finished?

  @task_endpoint.delete_tasks(uids: [uid]).await

  deleted?
end

#deleted?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/meilisearch/models/task.rb', line 77

def deleted?
  refresh unless @deleted

  !!@deleted
end

#enqueued?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/meilisearch/models/task.rb', line 34

def enqueued?
  refresh if status_enqueued?

  status_enqueued?
end

#errorObject



83
84
85
# File 'lib/meilisearch/models/task.rb', line 83

def error
  @metadata['error']
end

#failed?Boolean Also known as: has_failed?

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/meilisearch/models/task.rb', line 64

def failed?
  Utils.warn_on_unfinished_task(self) if unfinished?

  status == 'failed'
end

#finished?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/meilisearch/models/task.rb', line 53

def finished?
  !unfinished?
end

#processing?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/meilisearch/models/task.rb', line 40

def processing?
  refresh if status_processing? || status_enqueued?

  status_processing?
end

#refresh(with: nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/meilisearch/models/task.rb', line 87

def refresh(with: nil)
  self. = with || @task_endpoint.task(uid)

  self
rescue MeiliSearch::ApiError => e
  raise e unless e.http_code == 404

  @deleted = true

  self
end

#statusObject



30
31
32
# File 'lib/meilisearch/models/task.rb', line 30

def status
  @metadata['status']
end

#succeeded?Boolean Also known as: has_succeeded?

Returns:

  • (Boolean)


57
58
59
60
61
# File 'lib/meilisearch/models/task.rb', line 57

def succeeded?
  Utils.warn_on_unfinished_task(self) if unfinished?

  status == 'succeeded'
end

#to_hObject Also known as: to_hash



122
123
124
# File 'lib/meilisearch/models/task.rb', line 122

def to_h
  @metadata
end

#typeObject



26
27
28
# File 'lib/meilisearch/models/task.rb', line 26

def type
  @metadata['type']
end

#uidObject



22
23
24
# File 'lib/meilisearch/models/task.rb', line 22

def uid
  @metadata['taskUid']
end

#unfinished?Boolean Also known as: waiting?

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/meilisearch/models/task.rb', line 46

def unfinished?
  refresh if status_processing? || status_enqueued?

  status_processing? || status_enqueued?
end