Class: Embulk::Input::RedisCustomRestockNoti
- Inherits:
-
InputPlugin
- Object
- InputPlugin
- Embulk::Input::RedisCustomRestockNoti
- Defined in:
- lib/embulk/input/redis_custom_restock_noti.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.transaction(config, &control) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/embulk/input/redis_custom_restock_noti.rb', line 9 def self.transaction(config, &control) task = { 'host' => config.param('host', :string, :default => 'localhost'), 'port' => config.param('port', :integer, :default => 6379), 'db' => config.param('db', :integer, :default => 0), 'keys_pattern' => config.param('keys_pattern', :string, :default => ''), 'columns' => config.param('columns', :array, :default => []).inject({}){|a, col| a[col['name']] = col['type'].to_sym a }, 'rows' => 0 } columns = task['columns'].map.with_index{|(name, type), i| Column.new(i, name, type) } puts "Redis input started." commit_reports = yield(task, columns, 1) puts "Redis input finished. Commit reports = #{commit_reports.to_json}" return {} end |
Instance Method Details
#run ⇒ Object
def init
# initialization code:
@option1 = task["option1"]
@option2 = task["option2"]
@option3 = task["option3"]
end
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/embulk/input/redis_custom_restock_noti.rb', line 58 def run puts "Redis input thread #{@index}..." r = Redis.new(:host => @task['host'], :port => @task['port'], :db => @task['db']) r.keys("#{@task['keys_pattern']}").each do |key| k = key.split(':') v = r.zrange(key, 0, -1, :with_scores => true) v.each do |e| temp = Array.new temp.push(k[1]) # siteUid temp.push(k[3].split('-')[0]) # productCode temp.push(k[3].split('-')[1]) # size temp.push(e[0]) # customerUid temp.push(Time.at(e[1] / 1000)) # score(timestamp) @page_builder.add(temp) end @task['rows'] += 1 end @page_builder.finish # don't forget to call finish :-) commit_report = { "rows" => @task['rows'] } return commit_report end |