Class: Conductor::Tasks

Inherits:
Model
  • Object
show all
Defined in:
lib/nf-conductor/http/tasks.rb

Instance Attribute Summary

Attributes inherited from Model

#response, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

build

Constructor Details

#initialize(response) ⇒ Tasks

Returns a new instance of Tasks.



3
4
5
# File 'lib/nf-conductor/http/tasks.rb', line 3

def initialize(response)
  super(response)
end

Class Method Details

.acknowledge_task(task_id, worker_id: nil) ⇒ Object

POST /tasks/taskId/ack Ack Task is recieved



51
52
53
54
55
56
57
# File 'lib/nf-conductor/http/tasks.rb', line 51

def acknowledge_task(task_id, worker_id: nil)
  query_string = "/tasks/#{task_id}/ack?"
  query_string += "workerid=#{worker_id}" if worker_id

  response = Connection.new.post(query_string)
  Tasks.build(response)
end

.add_task_log(task_id, task_log) ⇒ Object

POST /tasks/taskId/log Log Task Execution Details



68
69
70
71
72
73
74
# File 'lib/nf-conductor/http/tasks.rb', line 68

def add_task_log(task_id, task_log)
  response = Connection.new.post(
    "/tasks/#{task_id}/log",
    { body: task_log.to_json }
  )
  Tasks.build(response)
end

.batch_poll_for_tasks(task_type, worker_id: nil, domain: nil, count: nil, timeout: nil) ⇒ Object

GET /tasks/poll/batch/tasktype batch Poll for a task of a certain type



10
11
12
13
14
15
16
17
18
19
# File 'lib/nf-conductor/http/tasks.rb', line 10

def batch_poll_for_tasks(task_type, worker_id: nil, domain: nil, count: nil, timeout: nil)
  query_string = "/tasks/poll/batch/#{task_type}?"
  query_string += "workerid=#{worker_id}" if worker_id
  query_string += "&domain=#{domain}" if domain
  query_string += "&count=#{count}" if count
  query_string += "&timeout=#{timeout}" if timeout

  response = Connection.new.get(query_string)
  Tasks.build(response)
end

.get_all_poll_dataObject

GET /tasks/queue/polldata/all Get the last poll data for a given task type



99
100
101
102
# File 'lib/nf-conductor/http/tasks.rb', line 99

def get_all_poll_data
  response = Connection.new.get("/tasks/queue/polldata/all")
  Tasks.build(response)
end

.get_all_tasksObject

GET /tasks/queue/all Get the details about each queue



154
155
156
157
# File 'lib/nf-conductor/http/tasks.rb', line 154

def get_all_tasks
  response = Connection.new.get("/tasks/queue/all")
  Tasks.build(response)
end

.get_all_tasks_verboseObject

GET /tasks/queue/all/verbose Get the details about each queue



85
86
87
88
# File 'lib/nf-conductor/http/tasks.rb', line 85

def get_all_tasks_verbose
  response = Connection.new.get("/tasks/queue/all/verbose")
  Tasks.build(response)
end

.get_in_progress_task_in_workflow(workflow_id, task_name) ⇒ Object

GET /tasks/in_progress/workflowId/taskRefName Get in progress task for a given workflow id.



34
35
36
37
# File 'lib/nf-conductor/http/tasks.rb', line 34

def get_in_progress_task_in_workflow(workflow_id, task_name)
  response = Connection.new.get("/tasks/in_progress/#{workflow_id}/#{task_name}")
  Tasks.build(response)
end

.get_in_progress_tasks(task_type, start_key: nil, count: nil) ⇒ Object

GET /tasks/in_progress/tasktype Get in progress tasks. The results are paginated.



23
24
25
26
27
28
29
30
# File 'lib/nf-conductor/http/tasks.rb', line 23

def get_in_progress_tasks(task_type, start_key: nil, count: nil)
  query_string = "/tasks/in_progress/#{task_type}?"
  query_string += "startKey=#{start_key}" if start_key
  query_string += "&count=#{count}" if count

  response = Connection.new.get(query_string)
  Tasks.build(response)
end

.get_poll_data(task_type) ⇒ Object

GET /tasks/queue/polldata Get the last poll data for a given task type



92
93
94
95
# File 'lib/nf-conductor/http/tasks.rb', line 92

def get_poll_data(task_type)
  response = Connection.new.get("/tasks/queue/polldata?taskType=#{task_type}")
  Tasks.build(response)
end

.get_queue_sizes(task_types) ⇒ Object

GET /tasks/queue/sizes Get Task type queue sizes



120
121
122
123
124
125
# File 'lib/nf-conductor/http/tasks.rb', line 120

def get_queue_sizes(task_types)
  task_types_query = task_types.is_a?(Array) ? task_types.to_query('taskType') : "taskType=#{taskType}"

  response = Connection.new.get("/tasks/queue/sizes?#{task_types_query}")
  Tasks.build(response)
end

.get_task(task_id) ⇒ Object

GET /tasks/taskId Get task by Id



161
162
163
164
# File 'lib/nf-conductor/http/tasks.rb', line 161

def get_task(task_id)
  response = Connection.new.get("/tasks/#{task_id}")
  Tasks.build(response)
end

.get_task_logs(task_id) ⇒ Object

GET /tasks/taskId/log Get Task Execution Logs



61
62
63
64
# File 'lib/nf-conductor/http/tasks.rb', line 61

def get_task_logs(task_id)
  response = Connection.new.get("/tasks/#{task_id}/log")
  Tasks.build(response)
end

.poll_task(task_type, worker_id: nil, domain: nil) ⇒ Object

GET /tasks/poll/tasktype Poll for a task of a certain type



129
130
131
132
133
134
135
136
# File 'lib/nf-conductor/http/tasks.rb', line 129

def poll_task(task_type, worker_id: nil, domain: nil)
  query_string = "/tasks/poll/#{task_type}?"
  query_string += "workerid=#{worker_id}" if worker_id
  query_string += "&domain=#{domain}" if domain

  response = Connection.new.get(query_string)
  Tasks.build(response)
end

.remove_task(task_type, task_id) ⇒ Object

DELETE /tasks/queue/taskType/taskId Remove Task from a Task type queue



78
79
80
81
# File 'lib/nf-conductor/http/tasks.rb', line 78

def remove_task(task_type, task_id)
  response = Connection.new.delete("/tasks/queue/#{task_type}/#{task_id}")
  Tasks.build(response)
end

.requeue_all_tasksObject

POST /tasks/queue/requeue Requeue pending tasks for all the running workflows



113
114
115
116
# File 'lib/nf-conductor/http/tasks.rb', line 113

def requeue_all_tasks
  response = Connection.new.post("/tasks/queue/requeue")
  Tasks.build(response)
end

.requeue_tasks(task_type) ⇒ Object

POST /tasks/queue/requeue/taskType Requeue pending tasks



106
107
108
109
# File 'lib/nf-conductor/http/tasks.rb', line 106

def requeue_tasks(task_type)
  response = Connection.new.post("/tasks/queue/requeue/#{task_type}")
  Tasks.build(response)
end

.search_task(start: nil, size: nil, sort: nil, free_text: nil, query: nil) ⇒ Object

GET /tasks/search Search for tasks based in payload and other parameters



140
141
142
143
144
145
146
147
148
149
150
# File 'lib/nf-conductor/http/tasks.rb', line 140

def search_task(start: nil, size: nil, sort: nil, free_text: nil, query: nil)
  query_string = "/tasks/search?"
  query_string += "start=#{start}" if start
  query_string += "&size=#{size}" if size
  query_string += "&sort=#{sort}" if sort
  query_string += "&freeText=#{free_text}" if free_text
  query_string += "&query=#{query}" if query

  response = Connection.new.get(query_string)
  Tasks.build(response)
end

.update_task(task_body) ⇒ Object

POST /tasks Update a task



41
42
43
44
45
46
47
# File 'lib/nf-conductor/http/tasks.rb', line 41

def update_task(task_body)
  response = Connection.new.post(
    "/tasks",
    { body: task_body.to_json }
  )
  Tasks.build(response)
end