Class: MeiliSearch::Models::Task
- Inherits:
-
Object
- Object
- MeiliSearch::Models::Task
- Extended by:
- Forwardable
- Defined in:
- lib/meilisearch/models/task.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #await(timeout_in_ms = 5000, interval_in_ms = 50) ⇒ Object
- #cancel ⇒ Object
- #cancelled? ⇒ Boolean
- #delete ⇒ Object
- #deleted? ⇒ Boolean
- #enqueued? ⇒ Boolean
- #error ⇒ Object
- #failed? ⇒ Boolean (also: #has_failed?)
- #finished? ⇒ Boolean
-
#initialize(metadata_hash, task_endpoint) ⇒ Task
constructor
A new instance of Task.
- #processing? ⇒ Boolean
- #refresh(with: nil) ⇒ Object
- #status ⇒ Object
- #succeeded? ⇒ Boolean (also: #has_succeeded?)
- #to_h ⇒ Object (also: #to_hash)
- #type ⇒ Object
- #uid ⇒ Object
- #unfinished? ⇒ Boolean (also: #waiting?)
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
#metadata ⇒ Object
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 |
#cancel ⇒ Object
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
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 |
#delete ⇒ Object
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
77 78 79 80 81 |
# File 'lib/meilisearch/models/task.rb', line 77 def deleted? refresh unless @deleted !!@deleted end |
#enqueued? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/meilisearch/models/task.rb', line 34 def enqueued? refresh if status_enqueued? status_enqueued? end |
#error ⇒ Object
83 84 85 |
# File 'lib/meilisearch/models/task.rb', line 83 def error @metadata['error'] end |
#failed? ⇒ Boolean Also known as: has_failed?
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
53 54 55 |
# File 'lib/meilisearch/models/task.rb', line 53 def finished? !unfinished? end |
#processing? ⇒ 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 |
#status ⇒ Object
30 31 32 |
# File 'lib/meilisearch/models/task.rb', line 30 def status @metadata['status'] end |
#succeeded? ⇒ Boolean Also known as: has_succeeded?
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_h ⇒ Object Also known as: to_hash
122 123 124 |
# File 'lib/meilisearch/models/task.rb', line 122 def to_h @metadata end |
#type ⇒ Object
26 27 28 |
# File 'lib/meilisearch/models/task.rb', line 26 def type @metadata['type'] end |
#uid ⇒ Object
22 23 24 |
# File 'lib/meilisearch/models/task.rb', line 22 def uid @metadata['taskUid'] end |
#unfinished? ⇒ Boolean Also known as: waiting?
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 |