Class: Mutx::Database::MongoConnector
- Inherits:
-
Object
- Object
- Mutx::Database::MongoConnector
- Defined in:
- lib/mutx/database/mongo_connector.rb
Class Method Summary collapse
- .active_tasks ⇒ Object
-
.all_results ⇒ Object
Returns all result $return [Array] results from results coll.
- .all_results_ids ⇒ Object
-
.all_tasks ⇒ Object
Returns all active tasks.
- .all_tests ⇒ Object
-
.clean_documentation ⇒ Object
Removes all documents of documentation from the DB.
-
.collections ⇒ Object
Returns a list of collections.
- .configuration ⇒ Object
-
.connected? ⇒ Boolean
COMMONS.
-
.cron_tasks ⇒ Object
Get cronneable tasks.
- .custom_param_for_name(custom_param_name) ⇒ Object
-
.custom_params_list ⇒ Object
CUSTOM PARAMS.
- .delete_custom_param(custom_param_id) ⇒ Object
- .delete_started_result(result_id) ⇒ Object
- .delete_task(task_id) ⇒ Object
- .drop_collections(hard = false) ⇒ Object
-
.ensure_int(value) ⇒ Object
Returns value as Fixnum if it is not $param [Object] value $return [Fixnum].
- .exist_custom_param_id?(param_id) ⇒ Boolean
- .exist_custom_param_name?(name) ⇒ Boolean
- .exist_task_with_custom_param_id?(custom_param_id) ⇒ Boolean
- .file_attached(result_id) ⇒ Object
- .find_results_for_key(key) ⇒ Object
- .find_results_for_status(status) ⇒ Object
- .find_results_for_task(task_name) ⇒ Object
- .force_close ⇒ Object
- .generate_id ⇒ Object
-
.get_all_documentation ⇒ Object
Return an array with all documents of documentation.
-
.get_custom_param(custom_param_id) ⇒ Object
Returns the entire record for a given id $param [String] custom_param_id $return [Hash] all custom param data.
-
.help_body(page) ⇒ Object
Returns the body html of a page.
-
.help_search(title) ⇒ Object
Returns a document from the DB for a certain title.
-
.help_title(page) ⇒ Object
Returns the title of a page.
- .input_data_for_id(id) ⇒ Object
-
.insert_commit(commit_info) ⇒ Object
Saves commit information $param [Hash] commit_info = => Fixnum, “commit_id” => String, “info” => String.
-
.insert_config(config_object) ⇒ Object
3 CONFIG.
- .insert_custom_param(custom_param_data) ⇒ Object
-
.insert_documentation(document) ⇒ Object
Inserts a document of documentation in the DB.
- .insert_input(input_data) ⇒ Object
-
.insert_result(result_data) ⇒ Object
Creates a result data andc returns de id for that register $param [Hash] execution_data $return [String] id for created result.
-
.insert_task(task_data) ⇒ Object
Inserts a task in tasks collection $param [Hash] task_data (see task_data_structure method).
-
.last_commit ⇒ Object
Returns last saved commit info $return [Hash] if exist.
-
.last_notified(quantity) ⇒ Object
get last N notified results.
- .last_result_for_task(task_id) ⇒ Object
- .mark_notified(result_id) ⇒ Object
- .only_running_for_task(task_name) ⇒ Object
- .only_started_for_task(task_name) ⇒ Object
- .param_id_for_name(custom_param_name) ⇒ Object
- .required_params_ids ⇒ Object
- .result_data_for_id(result_id) ⇒ Object
-
.results_for(task_id) ⇒ Object
Returns all results for a given task_id.
- .running(type) ⇒ Object
-
.running_for_task(task_name) ⇒ Object
Cron_start.
- .running_now ⇒ Object
- .running_results ⇒ Object
- .running_results_for_task_id(task_id) ⇒ Object
- .running_tasks ⇒ Object
- .running_tests ⇒ Object
-
.started! ⇒ Object
def self.update_only_started $results.update_many(=> “started”, => {“status” => “never_started”}) end.
-
.task_data_for(task_id) ⇒ Object
Returns the entire record for a given task name $param [String] task_name $return [Hash] all task data.
- .task_data_for_name(task_name) ⇒ Object
-
.task_id_for(task_name, type = nil) ⇒ Object
Returns the _id for a given task name $param [String] task_name $return [String] _id.
- .tasks(type = nil) ⇒ Object
- .tasks_names_with_custom_param_id(custom_param_id) ⇒ Object
- .tasks_with_custom_param_id(custom_param_id) ⇒ Object
-
.update_custom_param(custom_param_data) ⇒ Object
Update record for a given custom param $param [Hash] custom_param_data.
- .update_last_exec_time ⇒ Object
-
.update_result(result_data_structure) ⇒ Object
Updates result register with the given data.
-
.update_stop_bots_off(task_id) ⇒ Object
Cron_end.
- .update_stop_bots_on(task_id) ⇒ Object
-
.update_task(task_data) ⇒ Object
Update record for a given task $param [Hash] task_data.
- .update_tasks_with_custom_param_id(custom_param_id) ⇒ Object
Instance Method Summary collapse
- #authenticate(opts) ⇒ Object
-
#initialize(opts = {host: "localhost", port: 27017, username: nil, pass: nil}) ⇒ MongoConnector
constructor
include Mongo.
- #set_client(opts) ⇒ Object
- #set_commits_collection ⇒ Object
- #set_config_collection ⇒ Object
- #set_custom_param_collection ⇒ Object
- #set_db ⇒ Object
- #set_db_name ⇒ Object
- #set_documentation_collection ⇒ Object
- #set_input_collection ⇒ Object
- #set_logger ⇒ Object
- #set_results_collection ⇒ Object
- #set_task_collection ⇒ Object
Constructor Details
#initialize(opts = {host: "localhost", port: 27017, username: nil, pass: nil}) ⇒ MongoConnector
include Mongo
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mutx/database/mongo_connector.rb', line 11 def initialize(opts={host: "localhost", port: 27017, username: nil, pass: nil}) set_client(opts) set_db authenticate(opts) set_task_collection set_custom_param_collection set_config_collection set_results_collection set_commits_collection set_documentation_collection set_input_collection set_logger end |
Class Method Details
.active_tasks ⇒ Object
352 353 354 |
# File 'lib/mutx/database/mongo_connector.rb', line 352 def self.active_tasks self.all_tasks end |
.all_results ⇒ Object
Returns all result $return [Array] results from results coll
537 538 539 |
# File 'lib/mutx/database/mongo_connector.rb', line 537 def self.all_results $results.find({}).sort('_id' => -1).to_a end |
.all_results_ids ⇒ Object
541 542 543 |
# File 'lib/mutx/database/mongo_connector.rb', line 541 def self.all_results_ids $results.find({},{"_id" => 1}, :sort => ['_id', -1]).to_a end |
.all_tasks ⇒ Object
Returns all active tasks
266 267 268 |
# File 'lib/mutx/database/mongo_connector.rb', line 266 def self.all_tasks self.tasks end |
.all_tests ⇒ Object
270 271 272 |
# File 'lib/mutx/database/mongo_connector.rb', line 270 def self.all_tests self.tasks "test" end |
.clean_documentation ⇒ Object
Removes all documents of documentation from the DB
108 109 110 111 112 |
# File 'lib/mutx/database/mongo_connector.rb', line 108 def self.clean_documentation Mutx::Support::Log.debug "Cleanning db documentation collection" if Mutx::Support::Log $documentation.drop # $db.drop_collection("documentation") end |
.collections ⇒ Object
Returns a list of collections
166 167 168 |
# File 'lib/mutx/database/mongo_connector.rb', line 166 def self.collections ["tasks","results","custom_params","commit","configuration"] end |
.configuration ⇒ Object
571 572 573 574 |
# File 'lib/mutx/database/mongo_connector.rb', line 571 def self.configuration Mutx::Support::Log.debug "Getting db configuration data" if Mutx::Support::Log $configuration.find({}).to_a.first end |
.connected? ⇒ Boolean
COMMONS
152 153 154 155 156 157 158 |
# File 'lib/mutx/database/mongo_connector.rb', line 152 def self.connected? begin $db and true rescue false end end |
.cron_tasks ⇒ Object
Get cronneable tasks
258 259 260 261 262 263 |
# File 'lib/mutx/database/mongo_connector.rb', line 258 def self.cron_tasks Mutx::Support::Log.debug "Getting cronneable tasks" if Mutx::Support::Log criteria = {} criteria["cronneable"]="on" $tasks.find(criteria).sort("last_result" => -1).to_a end |
.custom_param_for_name(custom_param_name) ⇒ Object
429 430 431 432 |
# File 'lib/mutx/database/mongo_connector.rb', line 429 def self.custom_param_for_name custom_param_name Mutx::Support::Log.debug "Getting db custom param data for custom param name [#{custom_param_name}]" if Mutx::Support::Log $custom_params.find({"name" => custom_param_name}).to_a.first end |
.custom_params_list ⇒ Object
CUSTOM PARAMS
396 397 398 399 |
# File 'lib/mutx/database/mongo_connector.rb', line 396 def self.custom_params_list Mutx::Support::Log.debug "Getting db custom params list" if Mutx::Support::Log $custom_params.find({}).to_a end |
.delete_custom_param(custom_param_id) ⇒ Object
443 444 445 446 447 448 |
# File 'lib/mutx/database/mongo_connector.rb', line 443 def self.delete_custom_param custom_param_id Mutx::Support::Log.debug "Deleting db custom param for custom param id [#{custom_param_id}]" if Mutx::Support::Log $custom_params.delete_one({"_id" => custom_param_id}) self.update_tasks_with_custom_param_id(custom_param_id) end |
.delete_started_result(result_id) ⇒ Object
322 323 324 325 326 327 328 |
# File 'lib/mutx/database/mongo_connector.rb', line 322 def self.delete_started_result result_id Mutx::Support::Log.debug "Deletting db started result with id #{result_id}" if Mutx::Support::Log #Fix because MD5 #task_id = task_id.to_i if task_id.respond_to? :to_i res = $results.delete_one({"_id" => result_id}) res.n==1 end |
.delete_task(task_id) ⇒ Object
356 357 358 359 360 361 362 |
# File 'lib/mutx/database/mongo_connector.rb', line 356 def self.delete_task task_id Mutx::Support::Log.debug "Deletting db task with id #{task_id}" if Mutx::Support::Log #Fix because MD5 #task_id = task_id.to_i if task_id.respond_to? :to_i res = $tasks.delete_one({"_id" => task_id}) res.n==1 end |
.drop_collections(hard = false) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/mutx/database/mongo_connector.rb', line 170 def self.drop_collections hard=false collections_to_drop = self.collections ["custom_params","tasks"].each{|col| collections_to_drop.delete(col)} unless hard collections_to_drop.each do |collection| self..drop_collection(collection) if collection != "documentation" end end |
.ensure_int(value) ⇒ Object
Returns value as Fixnum if it is not $param [Object] value $return [Fixnum]
530 531 532 533 |
# File 'lib/mutx/database/mongo_connector.rb', line 530 def self.ensure_int(value) value = value.to_i if value.respond_to? :to_i value end |
.exist_custom_param_id?(param_id) ⇒ Boolean
438 439 440 441 |
# File 'lib/mutx/database/mongo_connector.rb', line 438 def self.exist_custom_param_id? param_id # !$custom_params.find({"_id" => param_id}).nil? $custom_params.find({"_id" => param_id}) end |
.exist_custom_param_name?(name) ⇒ Boolean
434 435 436 |
# File 'lib/mutx/database/mongo_connector.rb', line 434 def self.exist_custom_param_name? name !self.param_id_for_name(name).nil? end |
.exist_task_with_custom_param_id?(custom_param_id) ⇒ Boolean
456 457 458 |
# File 'lib/mutx/database/mongo_connector.rb', line 456 def self.exist_task_with_custom_param_id? custom_param_id !self.tasks_with_custom_param_id(custom_param_id).empty? end |
.file_attached(result_id) ⇒ Object
348 349 350 |
# File 'lib/mutx/database/mongo_connector.rb', line 348 def self.file_attached result_id $results.update_one({"_id" => result_id}, {"$set" => {"file_attached" => "yes"}}) end |
.find_results_for_key(key) ⇒ Object
545 546 547 |
# File 'lib/mutx/database/mongo_connector.rb', line 545 def self.find_results_for_key key $results.find({$or => [{"task.name" => /#{key}/}, {"execution_name" => /#{key}/ }, {"summary" => /#{key}/ }, {"command" => /#{key}/ }]}).to_a end |
.find_results_for_status(status) ⇒ Object
558 559 560 |
# File 'lib/mutx/database/mongo_connector.rb', line 558 def self.find_results_for_status status $results.find({$or => [{"summary" => /#{status}/}, {"status" => /#{status}/ }]},{"_id" => 1}).to_a end |
.find_results_for_task(task_name) ⇒ Object
553 554 555 556 |
# File 'lib/mutx/database/mongo_connector.rb', line 553 def self.find_results_for_task task_name task_id = self.task_id_for task_name self.results_for task_id end |
.force_close ⇒ Object
46 47 48 |
# File 'lib/mutx/database/mongo_connector.rb', line 46 def self.force_close $client = $client.close if $client end |
.generate_id ⇒ Object
160 161 162 163 |
# File 'lib/mutx/database/mongo_connector.rb', line 160 def self.generate_id value = Time.now.to_f.to_s.gsub( ".","")[0..12].to_i Digest::MD5.hexdigest(value.to_s) #Added MD5 to generate a mongo id end |
.get_all_documentation ⇒ Object
Return an array with all documents of documentation
121 122 123 124 |
# File 'lib/mutx/database/mongo_connector.rb', line 121 def self.get_all_documentation Mutx::Support::Log.debug "getting db all documentation" if Mutx::Support::Log $documentation.find().to_a end |
.get_custom_param(custom_param_id) ⇒ Object
Returns the entire record for a given id $param [String] custom_param_id $return [Hash] all custom param data
417 418 419 420 421 |
# File 'lib/mutx/database/mongo_connector.rb', line 417 def self.get_custom_param custom_param_id Mutx::Support::Log.debug "Getting db custom param data for custom param id #{custom_param_id}" if Mutx::Support::Log res = $custom_params.find({"_id" => custom_param_id}).to_a.first end |
.help_body(page) ⇒ Object
Returns the body html of a page
127 128 129 130 131 |
# File 'lib/mutx/database/mongo_connector.rb', line 127 def self.help_body page Mutx::Support::Log.debug "getting db help body" if Mutx::Support::Log result = $documentation.find({"title" => page}).to_a.first result["body"].to_s if result != nil end |
.help_search(title) ⇒ Object
Returns a document from the DB for a certain title
141 142 143 144 |
# File 'lib/mutx/database/mongo_connector.rb', line 141 def self.help_search title Mutx::Support::Log.debug "Searching on db help colection for title #{title}" if Mutx::Support::Log $documentation.find({:$or => [{ "title" => /#{title}/ },{ "title" => /#{title.upcase}/ },{ "body" => /#{title}/ }]}).to_a end |
.help_title(page) ⇒ Object
Returns the title of a page
134 135 136 137 138 |
# File 'lib/mutx/database/mongo_connector.rb', line 134 def self.help_title page Mutx::Support::Log.debug "getting db help title" if Mutx::Support::Log result = $documentation.find({"title" => page}).to_a.first result["title"].to_s.gsub('_', ' ').capitalize if result != nil end |
.input_data_for_id(id) ⇒ Object
383 384 385 386 387 |
# File 'lib/mutx/database/mongo_connector.rb', line 383 def self.input_data_for_id(id) res = $inputs.find({"_id" => id}) res = res.to_a.first if res.respond_to? :to_a res end |
.insert_commit(commit_info) ⇒ Object
Saves commit information $param [Hash] commit_info = => Fixnum, “commit_id” => String, “info” => String
188 189 190 |
# File 'lib/mutx/database/mongo_connector.rb', line 188 def self.insert_commit commit_info $commits.insert_one({"_id" => self.generate_id, "log" => commit_info}) end |
.insert_config(config_object) ⇒ Object
3 CONFIG
566 567 568 569 |
# File 'lib/mutx/database/mongo_connector.rb', line 566 def self.insert_config config_object Mutx::Support::Log.debug "db insert configuration [#{document}]" if Mutx::Support::Log $configuration.insert_one(config_object) end |
.insert_custom_param(custom_param_data) ⇒ Object
401 402 403 404 |
# File 'lib/mutx/database/mongo_connector.rb', line 401 def self.insert_custom_param custom_param_data Mutx::Support::Log.debug "Inserting custom param [#{custom_param_data}]" if Mutx::Support::Log $custom_params.insert_one(custom_param_data) end |
.insert_documentation(document) ⇒ Object
Inserts a document of documentation in the DB
115 116 117 118 |
# File 'lib/mutx/database/mongo_connector.rb', line 115 def self.insert_documentation document Mutx::Support::Log.debug "db insert documentation [#{document}]" if Mutx::Support::Log $documentation.insert_one(document) end |
.insert_input(input_data) ⇒ Object
378 379 380 381 |
# File 'lib/mutx/database/mongo_connector.rb', line 378 def self.insert_input input_data Mutx::Support::Log.debug "Inserting input [#{input_data}]" if Mutx::Support::Log $inputs.insert_one(input_data) end |
.insert_result(result_data) ⇒ Object
Creates a result data andc returns de id for that register $param [Hash] execution_data $return [String] id for created result
482 483 484 485 486 487 488 489 |
# File 'lib/mutx/database/mongo_connector.rb', line 482 def self.insert_result(result_data) begin $results.insert_one(result_data) true rescue false end end |
.insert_task(task_data) ⇒ Object
Inserts a task in tasks collection $param [Hash] task_data (see task_data_structure method)
208 209 210 211 |
# File 'lib/mutx/database/mongo_connector.rb', line 208 def self.insert_task task_data Mutx::Support::Log.debug "Inserting task [#{task_data}]" if Mutx::Support::Log $tasks.insert_one(task_data) end |
.last_commit ⇒ Object
Returns last saved commit info $return [Hash] if exist
194 195 196 197 198 199 200 |
# File 'lib/mutx/database/mongo_connector.rb', line 194 def self.last_commit Mutx::Support::Log.debug "Getting last commit" if Mutx::Support::Log data = $commits.find({}).to_a || [] unless data.empty? data.last["log"] end end |
.last_notified(quantity) ⇒ Object
get last N notified results
343 344 345 346 |
# File 'lib/mutx/database/mongo_connector.rb', line 343 def self.last_notified(quantity) #get last N notified results quantity = 5 if ( (quantity.to_i.eql? 0) || (quantity.to_i <= 0) ) $results.find({"notified" => "yes"}).limit(quantity.to_i).sort({"started_at" => -1}).to_a end |
.last_result_for_task(task_id) ⇒ Object
549 550 551 |
# File 'lib/mutx/database/mongo_connector.rb', line 549 def self.last_result_for_task task_id $results.find({}, :sort => ['_id', -1]) end |
.mark_notified(result_id) ⇒ Object
339 340 341 |
# File 'lib/mutx/database/mongo_connector.rb', line 339 def self.mark_notified result_id $results.update_one({"_id" => result_id}, {"$set" => {"notified" => "yes"}}) end |
.only_running_for_task(task_name) ⇒ Object
317 318 319 320 |
# File 'lib/mutx/database/mongo_connector.rb', line 317 def self.only_running_for_task task_name Mutx::Support::Log.debug "Getting db running for task name #{task_name}" if Mutx::Support::Log $results.find({"status" => "running", "task.name" => task_name}).to_a end |
.only_started_for_task(task_name) ⇒ Object
300 301 302 303 |
# File 'lib/mutx/database/mongo_connector.rb', line 300 def self.only_started_for_task task_name Mutx::Support::Log.debug "Getting db running for task name #{task_name}" if Mutx::Support::Log $results.find({"status" => "started", "task.name" => task_name}).to_a end |
.param_id_for_name(custom_param_name) ⇒ Object
423 424 425 426 427 |
# File 'lib/mutx/database/mongo_connector.rb', line 423 def self.param_id_for_name custom_param_name Mutx::Support::Log.debug "Getting db custom param id for custom param name [#{custom_param_name}]" if Mutx::Support::Log res = self.custom_param_for_name(custom_param_name) res["_id"] if res end |
.required_params_ids ⇒ Object
452 453 454 |
# File 'lib/mutx/database/mongo_connector.rb', line 452 def self.required_params_ids $custom_params.find({"required" => true},{:fields => ["_id"]}) end |
.result_data_for_id(result_id) ⇒ Object
510 511 512 513 514 515 516 |
# File 'lib/mutx/database/mongo_connector.rb', line 510 def self.result_data_for_id(result_id) #FIXED #result_id = self.ensure_int(result_id) #Cant convert MD5 to integer res = $results.find({"_id" => result_id}) res = res.to_a.first if res.respond_to? :to_a res end |
.results_for(task_id) ⇒ Object
Returns all results for a given task_id
492 493 494 495 496 497 |
# File 'lib/mutx/database/mongo_connector.rb', line 492 def self.results_for task_id #FIXED #$results.find({"task.id" => ensure_int(task_id)}).sort("started_at" => -1).to_a #Cant convert MD5 to integer $results.find({"task.id" => (task_id)}).sort("started_at" => -1).to_a end |
.running(type) ⇒ Object
287 288 289 290 291 292 |
# File 'lib/mutx/database/mongo_connector.rb', line 287 def self.running type Mutx::Support::Log.debug "Getting db running tasks" if Mutx::Support::Log $results.find({"status" => /started|running/, "task.type" => type}).to_a.map do |result| self.task_data_for result["task"]["id"] end.uniq end |
.running_for_task(task_name) ⇒ Object
Cron_start
295 296 297 298 |
# File 'lib/mutx/database/mongo_connector.rb', line 295 def self.running_for_task task_name Mutx::Support::Log.debug "Getting db running for task name #{task_name}" if Mutx::Support::Log $results.find({"status" => /started|running/, "task.name" => task_name}).to_a end |
.running_now ⇒ Object
282 283 284 285 |
# File 'lib/mutx/database/mongo_connector.rb', line 282 def self.running_now Mutx::Support::Log.debug "Getting db running tasks" if Mutx::Support::Log $results.find({"status" => /started|running/}).to_a end |
.running_results ⇒ Object
522 523 524 |
# File 'lib/mutx/database/mongo_connector.rb', line 522 def self.running_results $results.find({"status" => /running|started/}).to_a end |
.running_results_for_task_id(task_id) ⇒ Object
518 519 520 |
# File 'lib/mutx/database/mongo_connector.rb', line 518 def self.running_results_for_task_id task_id $results.find({"task.id" => task_id, "status" => /running|started/}).sort("started_at" => -1).to_a end |
.running_tasks ⇒ Object
274 275 276 |
# File 'lib/mutx/database/mongo_connector.rb', line 274 def self.running_tasks self.running "task" end |
.running_tests ⇒ Object
278 279 280 |
# File 'lib/mutx/database/mongo_connector.rb', line 278 def self.running_tests self.running "test" end |
.started! ⇒ Object
def self.update_only_started
$results.update_many({"status" => "started"}, {"$set" => {"status" => "never_started"}})
end
309 310 311 |
# File 'lib/mutx/database/mongo_connector.rb', line 309 def self.started! $results.find({"status" => "started"}).to_a end |
.task_data_for(task_id) ⇒ Object
Returns the entire record for a given task name $param [String] task_name $return [Hash] all task data
227 228 229 230 231 232 |
# File 'lib/mutx/database/mongo_connector.rb', line 227 def self.task_data_for task_id #task_id = task_id.to_i if task_id.respond_to? :to_i res = $tasks.find({"_id" => task_id}).to_a.first Mutx::Support::Log.debug "Getting db task data for task id #{task_id} => res = [#{res}]" if Mutx::Support::Log res end |
.task_data_for_name(task_name) ⇒ Object
234 235 236 237 |
# File 'lib/mutx/database/mongo_connector.rb', line 234 def self.task_data_for_name(task_name) Mutx::Support::Log.debug "Getting db task data for name #{task_name}" if Mutx::Support::Log $tasks.find({"name" => task_name}).to_a.first end |
.task_id_for(task_name, type = nil) ⇒ Object
Returns the _id for a given task name $param [String] task_name $return [String] _id
242 243 244 245 246 247 248 |
# File 'lib/mutx/database/mongo_connector.rb', line 242 def self.task_id_for task_name, type=nil Mutx::Support::Log.debug "Getting db task id for task name #{task_name} [type: #{type}]" if Mutx::Support::Log criteria = {"name" => task_name} criteria["type"] = type if type res = $tasks.find(criteria, {:fields => ["_id"]}).to_a.first res["_id"] if res end |
.tasks(type = nil) ⇒ Object
250 251 252 253 254 255 |
# File 'lib/mutx/database/mongo_connector.rb', line 250 def self.tasks type=nil Mutx::Support::Log.debug "Getting db tasks list [type: #{type}]" if Mutx::Support::Log criteria = {} criteria["type"]=type if type $tasks.find(criteria).sort("last_result" => -1).to_a end |
.tasks_names_with_custom_param_id(custom_param_id) ⇒ Object
460 461 462 463 464 |
# File 'lib/mutx/database/mongo_connector.rb', line 460 def self.tasks_names_with_custom_param_id custom_param_id self.tasks_with_custom_param_id(custom_param_id).map do |task| task["name"] end end |
.tasks_with_custom_param_id(custom_param_id) ⇒ Object
466 467 468 469 470 |
# File 'lib/mutx/database/mongo_connector.rb', line 466 def self.tasks_with_custom_param_id custom_param_id $tasks.find({}).to_a.select do |task| task["custom_params"].include? custom_param_id end end |
.update_custom_param(custom_param_data) ⇒ Object
Update record for a given custom param $param [Hash] custom_param_data
408 409 410 411 412 |
# File 'lib/mutx/database/mongo_connector.rb', line 408 def self.update_custom_param custom_param_data Mutx::Support::Log.debug "Updating db custom param [#{custom_param_data}]" if Mutx::Support::Log id = custom_param_data["_id"] $custom_params.update_one( {"_id" => custom_param_data["_id"]}, custom_param_data) end |
.update_last_exec_time ⇒ Object
313 314 315 |
# File 'lib/mutx/database/mongo_connector.rb', line 313 def self.update_last_exec_time $results.update_many({"cronneable" => "on"}, {"$set" => {"last_exec_time" => Time.now.utc}}) end |
.update_result(result_data_structure) ⇒ Object
Updates result register with the given data
501 502 503 504 505 506 507 508 |
# File 'lib/mutx/database/mongo_connector.rb', line 501 def self.update_result result_data_structure begin $results.update_one( {"_id" => result_data_structure["_id"]}, result_data_structure) true rescue false end end |
.update_stop_bots_off(task_id) ⇒ Object
Cron_end
331 332 333 |
# File 'lib/mutx/database/mongo_connector.rb', line 331 def self.update_stop_bots_off task_id $tasks.update_one({"_id" => task_id}, {"$set" => {"stop_bots" => "off"}}) end |
.update_stop_bots_on(task_id) ⇒ Object
335 336 337 |
# File 'lib/mutx/database/mongo_connector.rb', line 335 def self.update_stop_bots_on task_id $tasks.update_one({"_id" => task_id}, {"$set" => {"stop_bots" => "on"}}) end |
.update_task(task_data) ⇒ Object
Update record for a given task $param [Hash] task_data
215 216 217 218 219 220 221 222 |
# File 'lib/mutx/database/mongo_connector.rb', line 215 def self.update_task task_data #Fix because MD5 as _id #task_data["_id"] = task_data["_id"].to_i task_data.delete("action") Mutx::Support::Log.debug "Updating task [#{task_data}]" if Mutx::Support::Log res = $tasks.update_one( {"_id" => task_data["_id"]}, task_data) res.n == 1 end |
.update_tasks_with_custom_param_id(custom_param_id) ⇒ Object
364 365 366 367 368 369 |
# File 'lib/mutx/database/mongo_connector.rb', line 364 def self.update_tasks_with_custom_param_id custom_param_id self.tasks_with_custom_param_id(custom_param_id).each do |task_data| task_data["custom_params"].delete(custom_param_id) self.update_task task_data end end |
Instance Method Details
#authenticate(opts) ⇒ Object
57 58 59 60 |
# File 'lib/mutx/database/mongo_connector.rb', line 57 def authenticate opts Mutx::Support::Log.debug "db authenticating" if Mutx::Support::Log $auth = $db.authenticate(opts[:username], opts[:pass]) if opts[:username] and opts[:pass] end |
#set_client(opts) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/mutx/database/mongo_connector.rb', line 36 def set_client opts Mutx::Support::Log.debug "Setting db client" if Mutx::Support::Log if !$client #$client = Mongo::Client.new("mongodb://#{opts[:host]}:#{opts[:port]}/#{set_db_name}") $client = Mongo::Client.new([ "#{opts[:host]}:#{opts[:port]}" ], :database => "#{set_db_name}") else $client end end |
#set_commits_collection ⇒ Object
81 82 83 84 |
# File 'lib/mutx/database/mongo_connector.rb', line 81 def set_commits_collection Mutx::Support::Log.debug "Setting db commits collection" if Mutx::Support::Log $commits = $db.collection("commits") end |
#set_config_collection ⇒ Object
98 99 100 101 |
# File 'lib/mutx/database/mongo_connector.rb', line 98 def set_config_collection Mutx::Support::Log.debug "Setting db configuration collection" if Mutx::Support::Log $configuration = $db.collection("configuration") end |
#set_custom_param_collection ⇒ Object
69 70 71 72 73 |
# File 'lib/mutx/database/mongo_connector.rb', line 69 def set_custom_param_collection Mutx::Support::Log.debug "Setting db custom param collection" if Mutx::Support::Log $custom_params = $db.collection("custom_params") # $custom_params.ensure_index({"name" => 1}) end |
#set_db ⇒ Object
50 51 52 53 54 55 |
# File 'lib/mutx/database/mongo_connector.rb', line 50 def set_db Mutx::Support::Log.debug "Setting db" if Mutx::Support::Log $db = $client.database $client.close $client = nil end |
#set_db_name ⇒ Object
30 31 32 33 34 |
# File 'lib/mutx/database/mongo_connector.rb', line 30 def set_db_name project_name = Dir.pwd.split("/").last Mutx::Support::Log.debug "Setting db name: #{project_name}_mutx" if Mutx::Support::Log $db_name = "#{project_name}_mutx" end |
#set_documentation_collection ⇒ Object
93 94 95 96 |
# File 'lib/mutx/database/mongo_connector.rb', line 93 def set_documentation_collection Mutx::Support::Log.debug "Setting db documentation collection" if Mutx::Support::Log $documentation = $db.collection("documentation") end |
#set_input_collection ⇒ Object
75 76 77 78 79 |
# File 'lib/mutx/database/mongo_connector.rb', line 75 def set_input_collection Mutx::Support::Log.debug "Setting db Input collection" if Mutx::Support::Log $inputs = $db.collection("inputs") $inputs.indexes.create_one({"reference" => 1}) end |
#set_logger ⇒ Object
25 26 27 28 |
# File 'lib/mutx/database/mongo_connector.rb', line 25 def set_logger #Mongo::Logger.logger = ::Logger.new("mutx/logs/mongo.log") Mongo::Logger.logger.level = ::Logger::INFO end |
#set_results_collection ⇒ Object
86 87 88 89 90 91 |
# File 'lib/mutx/database/mongo_connector.rb', line 86 def set_results_collection Mutx::Support::Log.debug "Setting db results collection" if Mutx::Support::Log $results = $db.collection("results") # $results.ensure_index({"started_at" => 1}) # $results.ensure_index({"_id" => 1}) end |
#set_task_collection ⇒ Object
62 63 64 65 66 67 |
# File 'lib/mutx/database/mongo_connector.rb', line 62 def set_task_collection Mutx::Support::Log.debug "Setting db tasks collection" if Mutx::Support::Log $tasks = $db.collection("tasks") # $tasks.ensure_index({"name" => 1}) # $tasks.indexes.create_one({ "name" => 1 }, :unique => true) end |