Class: ArangoTask
- Inherits:
-
ArangoServer
- Object
- ArangoServer
- ArangoTask
- Defined in:
- lib/ArangoRB_Task.rb
Overview
AQL ===
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#idCache ⇒ Object
readonly
Returns the value of attribute idCache.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.tasks ⇒ Object
TESTED.
Instance Method Summary collapse
-
#create(offset: nil) ⇒ Object
TESTED.
- #database ⇒ Object
-
#destroy ⇒ Object
TESTED.
-
#initialize(database: @@database, id: nil, name: nil, type: nil, period: nil, command: nil, params: {}, created: nil) ⇒ ArangoTask
constructor
TESTED.
-
#retrieve ⇒ Object
TESTED.
- #to_hash ⇒ Object (also: #to_h)
Methods inherited from ArangoServer
address, async, async=, batch, cancelAsync, changePropertyWAL, checkPort, cluster, cluster=, clusterRoundtrip, clusterStatistics, collection, collection=, createDumpBatch, database, database=, databaseVersion, databases, default_server, destroyAllAsync, destroyAsync, destroyCluster, destroyDumpBatch, destroyExpiredAsync, echo, endpoints, execute, executeCluster, executeClusterHead, executeClusterPut, fetchAsync, flushWAL, graph, graph=, log, pendingAsync, prolongDumpBatch, propertyWAL, reload, request, restart, retrieveAsync, retrieveDoneAsync, retrievePendingAsync, return_result, return_result_async, role, server, serverId, shutdown, sleep, statistics, test, time, transactions, updateCluster, user, user=, username, users, verbose, verbose=, version
Constructor Details
#initialize(database: @@database, id: nil, name: nil, type: nil, period: nil, command: nil, params: {}, created: nil) ⇒ ArangoTask
TESTED
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ArangoRB_Task.rb', line 4 def initialize(database: @@database, id: nil, name: nil, type: nil, period: nil, command: nil, params: {}, created: nil) # TESTED if database.is_a?(String) @database = database elsif database.is_a?(ArangoDatabase) @database = database.database else raise "database should be a String or an ArangoDatabase instance, not a #{database.class}" end @id = id @name = name @type = type @period = period @command = command @params = params @created = created @idCache = "IND_#{@id}" end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def command @command end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def id @id end |
#idCache ⇒ Object (readonly)
Returns the value of attribute idCache.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def idCache @idCache end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def params @params end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def period @period end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/ArangoRB_Task.rb', line 22 def type @type end |
Class Method Details
.tasks ⇒ Object
TESTED
73 74 75 76 77 78 79 |
# File 'lib/ArangoRB_Task.rb', line 73 def self.tasks # TESTED result = get("/_db/#{@@database}/_api/tasks", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : result.map{|x| ArangoTask.new(id: x["id"], name: x["name"], type: x["type"], period: x["period"], created: x["created"], command: x["command"], database: x["database"])} end |
Instance Method Details
#create(offset: nil) ⇒ Object
TESTED
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/ArangoRB_Task.rb', line 81 def create offset: nil # TESTED body = { "name" => @name, "command" => @command, "period" => @period, "offset" => offset, "params" => @params }.delete_if{|k,v| v.nil?}.to_json request = @@request.merge({ :body => body }) if @id.nil? result = self.class.post("/_db/#{@database}/_api/tasks", request) else result = self.class.put("/_db/#{@database}/_api/tasks/#{@id}", request) end return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose unless result.is_a?(Hash) && result["error"] @id = result["id"] @name = result["name"] @type = result["type"] @period = result["period"] @created = result["created"] @command = result["command"] @database = result["database"] end result else return result["errorMessage"] if result.is_a?(Hash) && result["error"] @id = result["id"] @name = result["name"] @type = result["type"] @period = result["period"] @created = result["created"] @command = result["command"] @database = result["database"] self end end |
#database ⇒ Object
39 40 41 |
# File 'lib/ArangoRB_Task.rb', line 39 def database ArangoDatabase.new(database: @database) end |
#destroy ⇒ Object
TESTED
122 123 124 125 126 127 128 |
# File 'lib/ArangoRB_Task.rb', line 122 def destroy # TESTED result = self.class.delete("/_db/#{@database}/_api/tasks/#{@id}", @@request) return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response @@verbose ? result : (result.is_a?(Hash) && result["error"]) ? result["errorMessage"] : true end |
#retrieve ⇒ Object
TESTED
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ArangoRB_Task.rb', line 43 def retrieve # TESTED result = self.class.get("/_db/#{@database}/_api/tasks/#{@id}") return result.headers["x-arango-async-id"] if @@async == "store" return true if @@async result = result.parsed_response if @@verbose unless result.is_a?(Hash) && result["error"] @name = result["name"] @type = result["type"] @period = result["period"] @created = result["created"] @command = result["command"] @database = result["database"] end result else if result.is_a?(Hash) && result["error"] result["errorMessage"] else @name = result["name"] @type = result["type"] @period = result["period"] @created = result["created"] @command = result["command"] @database = result["database"] self end end end |
#to_hash ⇒ Object Also known as: to_h
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ArangoRB_Task.rb', line 24 def to_hash { "id" => @id, "name" => @name, "database" => @database, "type" => @type, "period" => @period, "create" => @created, "command" => @command, "params" => @params, "idCache" => @idCache }.delete_if{|k,v| v.nil?} end |