# frozen_string_literal: truemoduleSidekiqUniqueJobs# Interface to dealing with .lua files## @author Mikael Henriksson <mikael@mhenrixon.com>moduleScript## Module Caller provides the convenience method #call_script## @author Mikael Henriksson <mikael@mhenrixon.com>#moduleCallermodule_function# includes "SidekiqUniqueJobs::Connection"# @!parse include SidekiqUniqueJobs::ConnectionincludeSidekiqUniqueJobs::Connection## Convenience method to reduce typing,# calls redis lua scripts.### @overload call_script(file_name, keys, argv, conn)# Call script without options hash# @param [Symbol] file_name the name of the file# @param [Array<String>] keys to pass to the the script# @param [Array<String>] argv arguments to pass to the script# @param [Redis] conn a redis connection# @overload call_script(file_name, conn, keys:, argv:)# Call script with options hash# @param [Symbol] file_name the name of the file# @param [Redis] conn a redis connection# @param [Hash] options arguments to pass to the script file# @option options [Array] :keys to pass to the script# @option options [Array] :argv arguments to pass to the script## @return [true,false,String,Integer,Float,nil] returns the return value of the lua script#defcall_script(file_name,*args)conn,keys,argv=extract_args(*args)returndo_call(file_name,conn,keys,argv)ifconnpool=defined?(redis_pool)?redis_pool:nilredis(pool)do|new_conn|do_call(file_name,new_conn,keys,argv)endend# Only used to reduce a little bit of duplication# @see call_scriptdefdo_call(file_name,conn,keys,argv)argv=argv.dup.concat([now_f,debug_lua,max_history,file_name,redis_version,])Script.execute(file_name,conn,keys: keys,argv: argv)end## Utility method to allow both symbol keys and arguments## @overload call_script(file_name, keys, argv, conn)# Call script without options hash# @param [Symbol] file_name the name of the file# @param [Array<String>] keys to pass to the the script# @param [Array<String>] argv arguments to pass to the script# @param [Redis] conn a redis connection# @overload call_script(file_name, conn, keys:, argv:)# Call script with options hash# @param [Symbol] file_name the name of the file# @param [Redis] conn a redis connection# @param [Hash] options arguments to pass to the script file# @option options [Array] :keys to pass to the script# @option options [Array] :argv arguments to pass to the script## @return [Array<Redis, Array, Array>] <description>#defextract_args(*args)options=args.extract_options!ifoptions.length.positive?[args.pop,options.fetch(:keys){[]},options.fetch(:argv){[]}]elsekeys,argv=args.shift(2)keys||=[]argv||=[][args.pop,keys,argv]endend## @see SidekiqUniqueJobs#now_f#defnow_fSidekiqUniqueJobs.now_fend## @see SidekiqUniqueJobs::Config#debug_lua#defdebug_luaSidekiqUniqueJobs.config.debug_luaend## @see SidekiqUniqueJobs::Config#max_history#defmax_historySidekiqUniqueJobs.config.max_historyend## @see SidekiqUniqueJobs::Config#max_history#defredis_versionSidekiqUniqueJobs.config.redis_versionendendendend