路易吉覆盖到 S3



我有一个例行任务来上传和共享 S3 存储桶上的转储。虽然下面的代码有效,但由于某种原因它不想覆盖文件。

从文档中,我需要1( 定义两个并行执行的解决方案: path = luigi.Parameter(default=glob(DATA_DIR)[-2], batch_method=max)

2( 添加resources = {'overwrite_resource': 1}

虽然它适用于本地文件 - 但它不适用于 S3。

class report_to_S3(luigi.Task):
    client = S3Client()
    path = luigi.Parameter(default=glob(DATA_DIR)[-2], batch_method=max)
    local_dump_path = '../../../data/local_db_dump.csv'
    resources = {'overwrite_resource': 1}
    def requires(self):
        return upload_tweets(path=self.path)
    def output(self):
        self.s3_path = "s3://qclm-nyc-ct/dump/dump.csv"
        return S3Target(self.s3_path, client=self.client)
    def run(self):
        c = sqa.create_engine('postgresql:///qc_soc_media')
        df = pd.read_sql_query('SELECT id, user_id, timestamp, lat, lon, ct FROM tweets WHERE ct IS NOT NULL', c)
        N = len(df)
        df.to_csv(self.local_dump_path, index=None)
        self.client.put(self.local_dump_path, self.output().path,
                        headers={'Content-Type': 'application/csv'})
        send_S3_report(N)

if __name__ == '__main__':
    luigi.run(local_scheduler=True, main_task_cls=report_to_S3)

如果在 output(( 方法中指定的目标已经存在,则 run(( 方法将不会执行。您可能希望将时间戳处理到文件名中,或者创建另一个指示工作已完成的哨兵/标志。

最新更新