如何将参数传递到您的 ETL 作业中?
How to pass parameters into your ETL job?
我正在构建一个 ETL,它将 运行 在不同的源上,通过一个变量。
我如何执行我的工作(佣金任务)
Kiba.run(Kiba.parse(IO.read(etl_file),etl_file))
并为我的 etl_file
传递参数,然后用于其来源?
source MySourceClass(variable_from_rake_task)
看起来这里跟踪了这个 https://github.com/thbar/kiba/issues/18 and already asked here Pass Parameters to Kiba run Method
这里是 Kiba 的作者。
编辑:下面的解决方案仍然适用,但如果您需要更大的灵活性,您可以将 Kiba.parse 与块一起使用以获得更大的灵活性。有关详细说明,请参阅 https://github.com/thbar/kiba/wiki/Considerations-for-running-Kiba-jobs-programmatically-(from-Sidekiq,-Faktory,-Rake,-...)。
由于您正在使用 Rake 任务(而不是在并行环境中调用 Kiba,如 Resque 或 Sidekiq),您现在可以做的是利用 ENV
变量,如下所示:
CUSTOMER_IDS=10,11,12 bundle exec kiba etl/upsert-customers.etl
或者,如果您正在使用您编写的 rake 任务,您可以:
task :upsert_customers => :environment do
ENV['CUSTOMER_IDS'] = [10, 11, 12].join(',)
etl_file = 'etl/upsert-customers.etl'
Kiba.run(Kiba.parse(IO.read(etl_file),etl_file))
end
然后在upsert-customers.etl
:
# quick parsing
ids = ENV['CUSTOMER_ID'].split(',').map { |c| Integer(c) }
source Customers, ids: ids
如我之前所述,这仅适用于命令行模式,其中 ENV
可以安全使用。
对于并行执行,请确实跟踪 https://github.com/thbar/kiba/issues/18 因为我要处理它。
让我知道这是否能满足您的需求!
我正在构建一个 ETL,它将 运行 在不同的源上,通过一个变量。
我如何执行我的工作(佣金任务)
Kiba.run(Kiba.parse(IO.read(etl_file),etl_file))
并为我的 etl_file
传递参数,然后用于其来源?
source MySourceClass(variable_from_rake_task)
看起来这里跟踪了这个 https://github.com/thbar/kiba/issues/18 and already asked here Pass Parameters to Kiba run Method
这里是 Kiba 的作者。
编辑:下面的解决方案仍然适用,但如果您需要更大的灵活性,您可以将 Kiba.parse 与块一起使用以获得更大的灵活性。有关详细说明,请参阅 https://github.com/thbar/kiba/wiki/Considerations-for-running-Kiba-jobs-programmatically-(from-Sidekiq,-Faktory,-Rake,-...)。
由于您正在使用 Rake 任务(而不是在并行环境中调用 Kiba,如 Resque 或 Sidekiq),您现在可以做的是利用 ENV
变量,如下所示:
CUSTOMER_IDS=10,11,12 bundle exec kiba etl/upsert-customers.etl
或者,如果您正在使用您编写的 rake 任务,您可以:
task :upsert_customers => :environment do
ENV['CUSTOMER_IDS'] = [10, 11, 12].join(',)
etl_file = 'etl/upsert-customers.etl'
Kiba.run(Kiba.parse(IO.read(etl_file),etl_file))
end
然后在upsert-customers.etl
:
# quick parsing
ids = ENV['CUSTOMER_ID'].split(',').map { |c| Integer(c) }
source Customers, ids: ids
如我之前所述,这仅适用于命令行模式,其中 ENV
可以安全使用。
对于并行执行,请确实跟踪 https://github.com/thbar/kiba/issues/18 因为我要处理它。
让我知道这是否能满足您的需求!