idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
14,700 | def quit i = 0 @group . keys . each do | group | wait_until_done ( group ) do if i < 30 sleep 1 i += 1 print "." else break end end end @threads . each { | t | t . kill } puts " done." end | Quit - empty the queue and wait for remaining jobs to complete |
14,701 | def get_jobs_by_status ( status ) r = [ ] @group . values . each do | group | v = group . get_jobs_by_status ( status ) if v != nil and v != [ ] r += v end end return r end | Return an array of all jobs with the requested status . |
14,702 | def clean ( data_hash ) clean_hash = { } data_hash . each do | k , v | clean_hash [ k ] = v if v end clean_hash end | Removes nil values |
14,703 | def push ( j ) raise "invalid work" if j == nil j . job_id = IDManager . get if j . job_id == nil j . group = self @queue . push ( j ) @jobs_by_id [ j . job_id ] = j end | Add something to the work queue |
14,704 | def shift updated_queue = [ ] found_job = nil @queue . each do | job | if found_job || job . status == Executor :: STATUS_HOLDING updated_queue . push ( job ) elsif job . status == Executor :: STATUS_NONE found_job = job end end @queue = updated_queue @time_start = Time . now if @time_start == nil return found_job end | Take something from the queue |
14,705 | def results return self . get_jobs . map do | task | next if task == nil next if task . server == nil { :job_id => task . job_id , :name => task . info [ 0 ] , :host => task . server . name , :status => task . status , :error => task . error , :total => self . get_total_execution_time ( task . status , task . time_star... | Return a hash of the results |
14,706 | def sort! if @queue != nil @queue . sort! do | a , b | a . server . nickname <=> b . server . nickname end end end | Sort queue by server nickname |
14,707 | def get_jobs_by_status ( status ) r = [ ] @jobs_by_id . values . each do | i | r << i if i . status == status . to_sym || status . to_sym == :all end return r end | Get jobs by status |
14,708 | def done? return ( get_jobs_by_status ( Executor :: STATUS_NONE ) . size == 0 && get_jobs_by_status ( Executor :: STATUS_RUNNING ) . size == 0 && get_jobs_by_status ( Executor :: STATUS_DONE ) . size > 0 ) end | An execution group is done if nothing is queued or running and at least one job has completed . |
14,709 | def running? total_jobs_running = get_jobs_by_status ( Executor :: STATUS_NONE ) . size + get_jobs_by_status ( Executor :: STATUS_RUNNING ) . size + get_jobs_by_status ( Executor :: STATUS_RETRYING ) . size ( total_jobs_running > 0 ) end | Is this execution group running anything? |
14,710 | def queue ( id ) Log . debug "Queuing held job id #{id}" job = @jobs_by_id [ id ] job . owner = nil job . time_start = Time . now job . time_end = nil job . status = Executor :: STATUS_NONE self . push ( job ) end | Queue a held job by id |
14,711 | def cancel ( id ) Log . warn "Cancelling job id #{id}" job = @jobs_by_id [ id ] job . status = Executor :: STATUS_ERROR job . owner = nil job . time_end = Time . now @queue . delete ( job ) end | Cancel a job by id |
14,712 | def parse_search_results ( string , extraction_fields = nil ) xml = Nokogiri :: XML . parse ( string , "file:///rawfile.xml" ) items = xml / "/#{@xml_element_root}/*" total = items . length @logger . debug ( "Found #{total} articles in input pubmed file" ) items . each do | item | begin mArticle = RayyanFormats :: Targ... | user upload xml |
14,713 | def async_renew_and_publish_task ( channel_msg ) Concurrent :: Future . new ( executor : thread_pool ) do success = true begin combination = auth_channel_msg_2_combination ( channel_msg ) app_auths = app_authorizations ( combination ) renew ( combination [ :service_id ] , combination [ :credentials ] , app_auths ) metr... | Apart from renewing the auth of the combination received we also renew all the metrics of the associated application . The reason is that to renew a single metric we need to perform one call to 3scale and to renew all the limited metrics of an application we also need one . If the metric received does not have limits d... |
14,714 | def text ( name , locator ) define_method ( "#{name}" ) do platform . get_text ( locator ) end define_method ( "#{name}=" ) do | value | platform . enter_text ( value , locator ) end define_method ( "clear_#{name}" ) do platform . clear_text ( locator ) end define_method ( "#{name}_view" ) do Gametel :: Views :: Text .... | Generates methods to enter text into a text field clear the text field get the hint as well as the description |
14,715 | def button ( name , locator ) define_method ( name ) do platform . press_button ( locator ) end define_method ( "#{name}_view" ) do Gametel :: Views :: Button . new ( platform , locator ) end end | Generates a method to click a button and determine if it is enabled . |
14,716 | def list_item ( name , locator ) define_method ( name ) do platform . press_list_item ( locator ) end define_method ( "#{name}_view" ) do Gametel :: Views :: ListItem . new ( platform , locator ) end end | Generates one method to click a list item . |
14,717 | def checkbox ( name , locator ) define_method ( name ) do platform . click_checkbox ( locator ) end define_method ( "#{name}_checked?" ) do Gametel :: Views :: CheckBox . new ( platform , locator ) . checked? end define_method ( "#{name}_view" ) do Gametel :: Views :: CheckBox . new ( platform , locator ) end end | Generates one method to click a checkbox . |
14,718 | def radio_button ( name , locator ) define_method ( name ) do platform . click_radio_button ( locator ) end define_method ( "#{name}_view" ) do Gametel :: Views :: RadioButton . new ( platform , locator ) end end | Generates one method to click a radio button . |
14,719 | def image ( name , locator ) define_method ( "click_#{name}" ) do platform . click_image ( locator ) end define_method ( "wait_for_#{name}" ) do wait_until do platform . has_drawable? ( locator ) end end define_method ( "#{name}_view" ) do Gametel :: Views :: Image . new ( platform , locator ) end end | Generaes method to interact with an image . |
14,720 | def gather! :: Knowledge :: Initializer . new ( adapters : enabled_adapters , params : additionnal_params , setter : setter , variables : variables ) . run end | Gathers all the knowledge and put it into your app . |
14,721 | def enable_adapter ( name : , variables : nil ) _key , klass = available_adapters . find { | key , _klass | key . to_sym == name . to_sym } raise Knowledge :: AdapterNotFound , "Cannot find \"#{name}\" in available adapters" if klass . nil? @enabled_adapters [ name . to_sym ] = klass set_adapter_variables ( name : name... | Enables an adapter . |
14,722 | def register_adapter ( name : , klass : , enable : false , variables : nil ) @available_adapters [ name . to_sym ] = klass enable_adapter ( name : name ) if enable set_adapter_variables ( name : name , variables : variables ) end | Registers an adapter and enable it if asked . |
14,723 | def set_adapter_variables ( name : , variables : nil ) return unless variables case variables when Hash set_adapter_variables_by_hash ( name : name , variables : variables ) when String set_adapter_variables ( name : name , variables : yaml_content ( variables ) ) else raise "Unknown variables type #{variables.class}" ... | Sets variables for a given adapter . |
14,724 | def set_adapter_variables_by_hash ( name : , variables : ) variables = variables [ name . to_s ] if variables . key? ( name . to_s ) variables = variables [ name . to_sym ] if variables . key? ( name . to_sym ) @variables [ name . to_sym ] = variables end | Sets variables as a hash for a given adapter . |
14,725 | def use ( name : , enable : true ) adapter = self . class . adapters [ name . to_sym ] raise :: Knowledge :: RegisterError , "Unable to register following: #{name}" if adapter . nil? register_adapter ( name : name . to_sym , klass : adapter , enable : enable ) end | Registers & enables one of the lib s default adapters . |
14,726 | def fetch_variables_config ( path ) descriptor = yaml_content ( path ) @variables = descriptor [ :: Knowledge . config . environment . to_s ] || descriptor end | Opens the config file and sets the variable config . |
14,727 | def update ( options = { } ) libraries_to_update = ! exists? ? repo . all_libraries : options [ :libraries ] || changed_libraries read_and_transfer ( libraries_to_update ) if options [ :verbose ] puts ! exists? ? "Generating index for all #{libraries_to_update.size} libraries. Patience ... is a bitch" : ( libraries_to_... | Updates the index . |
14,728 | def set_command_namespaces lib_commands = @commands . inject ( { } ) { | t , e | ( t [ e . lib ] ||= [ ] ) << e ; t } namespace_libs = @libraries . select { | e | e . namespace ( e . indexed_namespace ) } namespace_libs . each { | lib | ( lib_commands [ lib . name ] || [ ] ) . each { | e | e . namespace = lib . namespa... | set namespaces for commands |
14,729 | def scrape ( file_string , line , mod , attribute = nil ) hash = scrape_file ( file_string , line ) || { } options = ( arr = hash . delete ( :option ) ) ? parse_option_comments ( arr , mod ) : { } hash . select { | k , v | v && ( attribute . nil? || attribute == k ) } . each do | k , v | hash [ k ] = EVAL_ATTRIBUTES . ... | Given a method s file string line number and defining module returns a hash of attributes defined for that method . |
14,730 | def scrape_file ( file_string , line ) lines = file_string . split ( "\n" ) saved = [ ] i = line - 2 while lines [ i ] =~ / \s \s \S / && i >= 0 saved << lines [ i ] i -= 1 end saved . empty? ? { } : splitter ( saved . reverse ) end | Scrapes a given string for commented |
14,731 | def build_nodes value = _target_column for key in _key_chain value [ key ] = { } unless value [ key ] value = value [ key ] end end | Call this method before set any values |
14,732 | def _key_chain handler = self key_chain = [ ] begin key_chain = handler . keys + key_chain handler = handler . parent end while handler key_chain end | Returns a key chain which includes all parent s keys and self keys |
14,733 | def result_to_hash ( result ) result . children . inject ( { } ) do | hash , node | hash [ node . name ] = node . text hash [ node . name ] = node . text . to_i if node . text && node . text =~ / \d / hash end end | Given a result xml element return a hash of the values we re interested in . |
14,734 | def append_history ( str ) return if @options [ :no_blanks ] && str . strip . empty? if history . include? ( str ) if @options [ :no_dups ] return if @options [ :no_move ] history . delete ( str ) end end history << str end | Append a string to the history buffer if enabled . |
14,735 | def parse_command_line begin opts = GetoptLong . new ( [ '--logfile' , '-l' , GetoptLong :: REQUIRED_ARGUMENT ] , [ '--verbose' , '-v' , GetoptLong :: NO_ARGUMENT ] , [ '--quiet' , '-q' , GetoptLong :: NO_ARGUMENT ] , [ '--concurrency' , '-c' , GetoptLong :: REQUIRED_ARGUMENT ] , [ '--delay' , '-d' , GetoptLong :: REQU... | Parse chimpd command line options |
14,736 | def spawn_webserver opts = { :BindAddress => @bind_address , :Port => @port , :MaxClients => 500 , :RequestTimeout => 120 , :DoNotReverseLookup => true } if not @verbose opts [ :Logger ] = WEBrick :: Log . new ( "/dev/null" ) opts [ :AccessLog ] = [ nil , nil ] end @server = :: WEBrick :: HTTPServer . new ( opts ) @ser... | Spawn a WEBrick Web server |
14,737 | def spawn_chimpd_submission_processor n = @concurrency / 4 n = 10 if n < 10 Log . debug "Logging into API..." begin c = Chimp . new c . interactive = false c . quiet = true c . run rescue StandardError end puts "chimpd #{VERSION} launched with #{@concurrency} workers" Log . debug "Spawning #{n} submission processing th... | Spawn threads to process submitted requests |
14,738 | def log ( exception ) msg = error_msg ( exception ) case exception when * NON_TEMP_ERRORS logger . error ( msg ) when * TEMP_ERRORS logger . warn ( msg ) else logger . error ( msg ) end end | For exceptions that are likely to require the user intervention we log errors . For example when the report could not be made because the 3scale client received an invalid provider key . On the other hand for errors that are likely to be temporary like when we could not connect with 3scale we log a warning . |
14,739 | def sms ( options = { } ) return @_message if @_sms_was_called && options . blank? m = @_message default_values = { } self . class . default . each do | k , v | default_values [ k ] = v . is_a? ( Proc ) ? instance_eval ( & v ) : v end options = options . reverse_merge ( default_values ) wrap_delivery_behavior! ( option... | The main method that creates the message and renders the SMS templates . There are two ways to call this method with a block or without a block . |
14,740 | def assets ( q , params = { } ) response = get ( "/v2/search.json" , params . merge ( query : q ) ) ACTV :: SearchResults . from_response ( response ) end | Initialized a new Client object |
14,741 | def organizer ( id , params = { } ) response = get ( "/v3/organizers/#{id}.json" , params ) ACTV :: Organizer . from_response response end | Returns an organizer with the specified ID |
14,742 | def find_asset_by_url ( url ) url_md5 = Digest :: MD5 . hexdigest ( url ) response = get ( "/v2/seourls/#{url_md5}?load_asset=true" ) ACTV :: Asset . from_response ( response ) end | Returns an asset with the specified url path |
14,743 | def articles ( q , params = { } ) response = get ( "/v2/search.json" , params . merge ( { query : q , category : 'articles' } ) ) ACTV :: ArticleSearchResults . from_response ( response ) end | Returns articles that match a specified query . |
14,744 | def article id , params = { } request_string = "/v2/assets/#{id}" is_preview , params = params_include_preview? params request_string += '/preview' if is_preview response = get "#{request_string}.json" , params article = ACTV :: Article . new response [ :body ] article . is_article? ? article : nil end | Returns an article with the specified ID |
14,745 | def popular_interests ( params = { } , options = { } ) response = get ( "/interest/_search" , params , options ) ACTV :: PopularInterestSearchResults . from_response ( response ) end | Returns popular interests |
14,746 | def event_results ( assetId , assetTypeId , options = { } ) begin response = get ( "/api/v1/events/#{assetId}/#{assetTypeId}.json" , { } , options ) ACTV :: EventResult . from_response ( response ) rescue nil end end | Returns a result with the specified asset ID and asset type ID |
14,747 | def multi_search ( * options ) results = [ ] query_index = 0 options_hash = options . inject ( { } ) do | hash , options | hash . merge! "query_#{query_index}" => "[#{URI.encode_www_form options}]" query_index += 1 hash end if options_hash . present? response = get ( "/v2/multisearch" , options_hash ) response [ :body ... | Returns results with multiple queries |
14,748 | def request ( method , path , params , options ) uri = options [ :endpoint ] || @endpoint uri = URI ( uri ) unless uri . respond_to? ( :host ) uri += path request_headers = { } params [ :api_key ] = @api_key unless @api_key . nil? if self . credentials? signature_params = if [ :post , :put ] . include? ( method . to_sy... | Perform an HTTP Request |
14,749 | def bulk_log_data ( registers = register_list ) registers . map do | reg | read_scaled_range ( reg . start , reg . count ) end . flatten end | More optimized data fetch . Gets an array of address range structs |
14,750 | def bulk_log_header ( registers = register_list ) registers . map do | reg | range_address_header ( reg . start , reg . count ) end . flatten end | Get the headers for the bulk_log data |
14,751 | def key ( * keys ) options = keys . extract_options! raise ArgumentError . new ( "has_settings: Option :defaults expected, but got #{options.keys.join(', ')}" ) unless options . blank? || ( options . keys == [ :defaults ] ) keys . each do | key_name | unless key_name . is_a? ( Symbol ) || key_name . is_a? ( String ) ra... | Declare a key with default values |
14,752 | def attr ( value , options = { } ) unless value . is_a? ( Symbol ) || value . is_a? ( String ) raise ArgumentError . new ( "has_settings: symbol expected, but got a #{value.class}" ) end raise ArgumentError . new ( "has_settings: Option :default expected, but got #{options.keys.join(', ')}" ) unless options . blank? ||... | Declare an attribute with default value |
14,753 | def content_encoding if content_type = headers [ "content-type" ] mime_type , charset = content_type . split ( SEMICOLON , 2 ) charset = charset [ CHARSET_OFFSET ] if charset charset ||= EMPTY if charset . empty? and mime_type . start_with? ( "text/" ) Encoding :: UTF_8 elsif charset . empty? Encoding :: BINARY else EN... | Determine content encoding by reviewing message headers . |
14,754 | def write_header ( key , value ) key = decode_header ( key ) @headers [ key ] = decode_header ( value ) unless @headers . has_key? ( key ) end | Write a single header to this frame . |
14,755 | def stations resp = self . connection . request ( :get , Citibike :: Station . path ) return resp if @options [ :unwrapped ] Citibike :: Responses :: Station . new ( resp ) end | Wrapper around a call to list all stations |
14,756 | def find_destination ( destination_name ) destination = @destinations [ destination_name ] if destination . nil? raise MessageDriver :: NoSuchDestinationError , "no destination #{destination_name} has been configured" end destination end | Find a previously declared Destination |
14,757 | def extract_metadata @metadata = { } convert do | current | current . each_line . drop_while do | line | next false if line !~ / \+ / key , value = $1 , $2 @metadata [ key . to_sym ] = value end . join ( '' ) end end | Extract metadata from the document . |
14,758 | def embed_transformer lambda do | env | node = env [ :node ] node_name = env [ :node_name ] return if env [ :is_whitelisted ] || ! env [ :node ] . element? return unless %w[ iframe embed ] . include? env [ :node_name ] uri = URI ( env [ :node ] [ 'src' ] ) return unless uri . host =~ allowed_iframe_hosts Sanitize . cle... | A sanitize transformer that will check the document for IFRAME tags and validate them against + allowed_iframe_hosts + . |
14,759 | def append_tenant_theme_to_assets ( * assets ) assets . map! do | asset | if should_add_tenant_theme_to_asset? ( asset ) && current_tenant "#{current_tenant.themes.first}/#{asset}" else asset end end assets end | updates the asset list with tenant theme where it s necessary |
14,760 | def authenticate ( user_name , password ) options = { } options [ :Username ] = user_name options [ :Password ] = password response = self . class . post ( '/' , :body => self . class . build_XML_request ( 'Auth.Authenticate' , self , options ) ) self . class . response_valid? response if response [ 'YourMembership_Res... | Authenticates a member s username and password and binds them to the current API session . |
14,761 | def sorted_metrics ( metrics , hierarchy ) parent_metrics = hierarchy . keys child_metrics = metrics - parent_metrics parent_metrics + child_metrics end | Returns an array of metric names . The array is guaranteed to have all the parents first and then the rest . In 3scale metric hierarchies only have 2 levels . In other words a metric that has a parent cannot have children . |
14,762 | def all_near ( obj , dist ) @data . select do | d | if d . id == obj . id false else d . distance_from ( obj . latitude , obj . longitude ) < dist end end end | Returns every object within dist miles of obj |
14,763 | def method_missing ( sym , * args , & block ) if self . data . respond_to? ( sym ) return self . data . send ( sym , * args , & block ) end super end | Delegates any undefined methods to the underlying data |
14,764 | def run while @never_exit work_item = ChimpQueue . instance . shift ( ) begin if work_item != nil job_uuid = work_item . job_uuid group = work_item . group . group_id work_item . retry_count = @retry_count work_item . owner = Thread . current . object_id ChimpDaemon . instance . semaphore . synchronize do if ChimpDaemo... | Grab work items from the ChimpQueue and process them Only stop is |
14,765 | def enforce_count ( args , params , diff = 0 ) num_args = args . size num_params = params == 'V' ? 0 : params . size + diff if num_args != num_params raise ArgumentError , "wrong number of parameters: expected #{num_params}, got #{num_args}" end end | Ensures that args count is equal to params count plus diff |
14,766 | def return_enum lambda do | api , * args , & block | WinGui . enforce_count ( args , api . prototype , - 1 ) handles = [ ] cb = if block callback ( 'LP' , 'I' , & block ) else callback ( 'LP' , 'I' ) do | handle , message | handles << handle true end end args [ api . prototype . find_index ( 'K' ) , 0 ] = cb api . call... | Procedure that calls api function expecting a callback . If runtime block is given it is converted into actual callback otherwise procedure returns an array of all handles pushed into callback by api enumeration |
14,767 | def alliterativity words = self . downcase . gsub ( / \s / , '' ) . split leading_letters = words . map ( & :chr ) leading_letter_counts = leading_letters . inject ( { } ) do | result , letter | result [ letter ] ||= 0 result [ letter ] += 1 result end most_used_count = leading_letter_counts . max_by { | kv | kv . last... | A score between 0 and 1 representing the level of alliteration |
14,768 | def n_plus ( places , word_list ) analysis = Analysis . new ( self , :nouns => word_list ) substitutor = Substitutor . new ( analysis ) substitutor . replace ( :nouns ) . increment ( places ) end | Replace the words in the word list with the word n places after it |
14,769 | def snowball? words = self . split self . chaterism? && words . first . length < words . last . length end | Returns true if each word is one letter larger than the previous |
14,770 | def chaterism? words = self . gsub ( / \s /i , '' ) . split flen , llen = words . first . length , words . last . length direction = flen > llen ? :downto : :upto words . map ( & :length ) == flen . send ( direction , llen ) . to_a end | Returns true if the string is a sequence of words in each of which is one letter larger than the previous or each word in the sequence is one letter less than the previous |
14,771 | def sync_window ( edit_buffer , edit_posn ) unless check_margins ( edit_buffer . length , edit_posn ) window_buffer . clear @show_prompt = true end image = build_screen_image ( edit_buffer ) update_screen ( image ) @window_buffer = image end | Keep the edit window in sync! |
14,772 | def build_screen_image ( edit_buffer ) working_region = edit_buffer [ left_margin .. right_margin ] if ( mask = @options [ :secret_mask ] ) mask [ 0 ] * working_region . length else working_region end . ljust ( active_width ) end | Compute what should be on the screen . |
14,773 | def update_screen ( image ) if @show_prompt MiniTerm . print ( "\r#{prompt.text}\r" ) @show_prompt = false end ( 0 ... active_width ) . each do | index | if ( image_char = image [ index ] ) != window_buffer [ index ] MiniTerm . set_posn ( column : prompt . length + index ) MiniTerm . print ( image_char ) end end end | Bring the screen into agreement with the image . |
14,774 | def __mandate_memoize ( method_name ) memoizer = Module . new do define_method method_name do @__mandate_memoized_results ||= { } if @__mandate_memoized_results . include? ( method_name ) @__mandate_memoized_results [ method_name ] else @__mandate_memoized_results [ method_name ] = super ( ) end end end prepend memoize... | Create an anonymous module that defines a method with the same name as main method being defined . Add some memoize code to check whether the method has been previously called or not . If it s not been then call the underlying method and store the result . |
14,775 | def call ( * , ** , & block ) pid = fork_and_return_pid ( & block ) write . close result = read . read Process . wait ( pid ) Marshal . load ( result ) end | Run the block inside a subprocess and return the value . |
14,776 | def get_body uri = URI . parse ( @url ) @response = get_response ( uri ) ( @options [ :any_response ] || @response . code == '200' ) ? @response . body : nil rescue @options [ :raise_error ] ? raise : puts ( "Error: GET '#{@url}' -> #{$!.class}: #{$!.message}" ) end | Returns body string if successful or nil if not . |
14,777 | def parse_body ( body ) format = determine_format ( @options [ :parse ] ) case format when :json unless :: Boson :: Util . safe_require 'json' return puts ( "Install the json gem to parse json: sudo gem install json" ) end JSON . parse body when :yaml YAML :: load body else puts "Can't parse this format." end rescue @o... | Returns nil if dependencies or parsing fails |
14,778 | def write_csv ( file_name , records ) line_number = exporter . connection_adapter . write ( local_file ( file_name ) , records ) end | Writes all results to one file for future splitting . |
14,779 | def file_key_in_format ( file_name , format ) if format == "gzip" self . class . s3_file_key exporter . source_table , gzipped ( file_name ) else self . class . s3_file_key exporter . source_table , file_name end end | Returns the s3 key to be used |
14,780 | def upload_csv ( files ) files . each do | file | basename = File . basename ( file ) next if basename == File . basename ( exporter . replication . key ) RailsRedshiftReplicator . logger . info I18n . t ( :uploading_notice , file : file , key : self . class . s3_file_key ( exporter . source_table , basename ) , scope ... | Uploads splitted CSVs |
14,781 | def run_with_retry ( & block ) Log . debug "Running job '#{@job_id}' with status '#{@status}'" ChimpDaemon . instance . semaphore . synchronize do if @group . started >= @concurrency && @delay . nonzero? Log . info "[#{@job_uuid}] Sleeping #{@delay} seconds between tasks" sleep @delay end @group . started += 1 end @sta... | Run a unit of work with retries This is called from the subclass with a code block to yield to |
14,782 | def transfer_funds raise "payment must be paid" if ! payment . paid? bank_account = PagarMe :: BankAccount . new ( bank_account_attributes . delete ( :bank_account ) ) bank_account . create raise "unable to create an bank account" unless bank_account . id . present? transfer = PagarMe :: Transfer . new ( { bank_account... | Transfer payment amount to payer bank account via transfers API |
14,783 | def run queue = ChimpQueue . instance arguments = [ ] ARGV . each { | arg | arguments << arg . clone } self . cli_args = arguments . collect { | param | param . gsub ( / / ) do | match | match = '"' + match + '"' end } . join ( " " ) parse_command_line if @interactive check_option_validity if @interactive disable_loggi... | Set up reasonable defaults |
14,784 | def check_option_validity if @hold && ! @array_names . empty? puts "ERROR: Holding of array objects is not yet supported" exit 1 end if @tags . empty? and @array_names . empty? and @deployment_names . empty? and not @chimpd_wait_until_done puts "ERROR: Please select the objects to operate upon." help exit 1 end if not ... | Check for any invalid combinations of command line options |
14,785 | def get_servers_by_tag ( tags ) if @match_all t = tags . join ( "&tag=" ) filter = "tag=#{t}" servers = Connection . instances ( filter ) else t = tags . join ( "," ) filter = "tag=#{t}" servers = Connection . instances ( filter ) end if servers . nil? if @ignore_errors Log . warn "[#{Chimp.get_job_uuid}] Tag query ret... | Api1 . 6 equivalent |
14,786 | def verify_tagged_instances ( servers , tags ) array_list = servers if @match_all matching_servers = array_list . select { | instance | ( tags - instance [ 'tags' ] ) . empty? } else matching_servers = array_list . select { | instance | tags . any? { | tag | instance [ 'tags' ] . include? ( tag ) } } end if matching_se... | Verify that all returned instances from the API match our tag request |
14,787 | def get_hrefs_for_arrays ( names ) result = [ ] arrays_hrefs = [ ] if names . size > 0 names . each do | array_name | begin Log . debug "[#{Chimp.get_job_uuid}] Making API 1.5 call: client.server_arrays.index(:filter => [#{array_name}])" tries ||= 3 result = Connection . client . server_arrays . index ( :filter => [ "n... | Given some array names return the arrays hrefs Api1 . 5 |
14,788 | def detect_server_template ( servers ) Log . debug "[#{Chimp.get_job_uuid}] Looking for server template" st = [ ] if servers [ 0 ] . nil? return ( st ) end st += servers . collect { | s | [ s [ 'href' ] , s [ 'server_template' ] ] } . uniq { | a | a [ 0 ] } Log . debug "[#{Chimp.get_job_uuid}] Found server templates" r... | Given a list of servers |
14,789 | def detect_right_script ( st , script ) Log . debug "[#{Chimp.get_job_uuid}] Looking for rightscript" executable = nil if @op_scripts . nil? @op_scripts = [ ] end if st . nil? return executable end @op_scripts = extract_operational_scripts ( st ) if @script == "" and @script != nil reduce_to_common_scripts ( st . size ... | This function returns |
14,790 | def reduce_to_common_scripts ( number_of_st ) counts = Hash . new 0 @op_scripts . each { | s | counts [ s [ 0 ] ] += 1 } b = @op_scripts . inject ( { } ) do | res , row | res [ row [ 0 ] ] ||= [ ] res [ row [ 0 ] ] << row [ 1 ] res end b . inject ( [ ] ) do | res , ( key , values ) | res << [ key , values . first ] if ... | Takes the number of st s to search in and reduces |
14,791 | def extract_operational_scripts ( st ) op_scripts = [ ] size = st . size st . each do | s | Log . debug "[#{Chimp.get_job_uuid}] Making API 1.5 call: client.resource (ST)" begin tries ||= 3 temp = Connection . client . resource ( s [ 1 ] [ 'href' ] ) Log . debug "[#{Chimp.get_job_uuid}] API 1.5 call client.resource (ST... | Returns all matching operational scripts in the st list passed |
14,792 | def queue_runner ( concurrency , delay , retry_count , progress ) queue = ChimpQueue . instance queue . max_threads = concurrency queue . delay = delay queue . retry_count = retry_count total_queue_size = queue . size puts "Executing..." unless progress or not quiet pbar = ProgressBar . new ( "Executing" , 100 ) if pro... | Execute the user s command and provide for retrys etc . |
14,793 | def verify_results ( group = :default ) failed_workers , results_display = get_results ( group ) if failed_workers . empty? @paused = false return "continue" end verify ( "The following objects failed:" , results_display , false ) unless @paused if ! @prompt || @paused @paused = true sleep 15 return "pause" end while t... | Allow user to verify results and retry if necessary |
14,794 | def get_results ( group_name ) queue = ChimpQueue . instance Log . debug ( "getting results for group #{group_name}" ) results = queue . group [ @group ] . results ( ) failed_workers = [ ] results_display = [ ] results . each do | result | next if result == nil if result [ :status ] == :error name = result [ :host ] ||... | Get the results from the QueueRunner and format them in a way that s easy to display to the user |
14,795 | def process Chimp . set_failure ( false ) Chimp . set_job_uuid ( job_uuid ) Log . debug "[#{job_uuid}] Processing task" Log . debug "[#{job_uuid}] Trying to get array_info" unless Chimp . failure get_array_info unless Chimp . failure Log . debug "[#{job_uuid}] Trying to get server_info" unless Chimp . failure get_serve... | Completely process a non - interactive chimp object command This is used by chimpd when processing a task . |
14,796 | def chimpd_wait_until_done local_queue = ChimpQueue . instance $stdout . print "Waiting for chimpd jobs to complete for group #{@group}..." begin while ! @dry_run local_queue = ChimpQueue . instance sleeping_counter = 0 while true local_queue . reset! begin all = ChimpDaemonClient . retrieve_group_info ( @chimpd_host ,... | Connect to chimpd and wait for the work queue to empty and prompt the user if there are any errors . |
14,797 | def start ( connection_or_group ) @connection = connection_or_group @channel = AMQP :: Channel . new ( @connection ) queue_options = { } name = queue_name if queue_type == :broadcast queue_options [ :exclusive ] = true queue_options [ :auto_delete ] = true name = "#{Socket.gethostname}-#{Process.pid}-#{self.object_id}"... | Starts the Worker with the given connection or group name |
14,798 | def click ( id ) h = child ( id ) . handle rectangle = [ 0 , 0 , 0 , 0 ] . pack 'LLLL' get_window_rect h , rectangle left , top , right , bottom = rectangle . unpack 'LLLL' center = [ ( left + right ) / 2 , ( top + bottom ) / 2 ] set_cursor_pos * center mouse_event MOUSEEVENTF_LEFTDOWN , 0 , 0 , 0 , 0 mouse_event MOUSE... | emulate click of the control identified by id |
14,799 | def load_explorer_data document = Nokogiri :: XML ( Faraday . get ( @song_explorer_url ) . body ) @id = document . search ( 'songExplorer' ) . first [ 'musicId' ] end | Unfortunately the Tuner API track JSON doesn t include the musicId a track identifier that s constant among different user sessions . However we can fetch it via the Song s Explorer XML URL . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.