1、mac 上安装luigi

pip install luigi

pip install boto3 (luigi依赖 boto3)

2、基本概念

class Streams(luigi.Task):

    """

    Faked version right now, just generates bogus data.

    """

    date = luigi.DateParameter()

    def run(self):

        """

        Generates bogus data and writes it into the :py:meth:`~.Streams.output` target.

        """

        with self.output().open('w') as output:

            for _ in range():

                output.write('{} {} {}\n'.format(

                    random.randint(, ),

                    random.randint(, ),

                    random.randint(, )))

    def output(self):

        """

        Returns the target output for this task.

        In this case, a successful execution of this task will create a file in the local file system.

        :return: the target output for this task.

        :rtype: object (:py:class:`luigi.target.Target`)

        """

        return luigi.LocalTarget(self.date.strftime('data/streams_%Y_%m_%d_faked.tsv'))

class AggregateArtists(luigi.Task):
"""
This task runs over the target data returned by :py:meth:`~/.Streams.output` and
writes the result into its :py:meth:`~.AggregateArtists.output` target (local file).
""" date_interval = luigi.DateIntervalParameter() def output(self):
"""
Returns the target output for this task.
In this case, a successful execution of this task will create a file on the local filesystem. :return: the target output for this task.
:rtype: object (:py:class:`luigi.target.Target`)
"""
return luigi.LocalTarget("data/artist_streams_{}.tsv".format(self.date_interval)) def requires(self):
"""
This task's dependencies: * :py:class:`~.Streams` :return: list of object (:py:class:`luigi.task.Task`)
"""
return [Streams(date) for date in self.date_interval] def run(self):
artist_count = defaultdict(int) for t in self.input():
with t.open('r') as in_file:
for line in in_file:
_, artist, track = line.strip().split()
artist_count[artist] += with self.output().open('w') as out_file:
for artist, count in six.iteritems(artist_count):
out_file.write('{}\t{}\n'.format(artist, count))

run()是这个task要执行的内容

requires()是这个task所依赖的任务,这里依赖一系列的Stream

output()是这个task的输出

input()这个是所依赖的task产生的输出

二、使用central planner

先用

luigid --background --pidfile <PATH_TO_PIDFILE> --logdir <PATH_TO_LOGDIR> --state-path <PATH_TO_STATEFILE>

打开liguid server

然后运行任务,比如:

luigi --module top_artists2 Top10Artists  --date-interval 2012-06

注意,要去掉 --local-scheduler

然后可以用 localhost:8082来访问现在的任务

如果A -> B,A依赖B,那么B的output可以在A里面直接用input()来使用,如果B的output是若干文件的话,那么在A中的input()也是若干文件,可以用for循环来读取


luigi 学习的更多相关文章

  1. luigi学习3-使用luigid

    --local-scheduler的方式只适用于开发调试阶段,当你真正要把程序部署到一个产品时,我们推荐使用luigid服务. 使用luigid服务不但能提供锁服务(防止一个任务被多个进程重复执行), ...

  2. luigi学习9--执行模型

    luigi的执行和触发模型非常简单. 一.luigi的执行模型 当你执行一个luigi的工作流的时候,worker调度所有的task,并且执行task在一个单独的进程中. 这种scheme最大的好处是 ...

  3. luigi学习8--使用中央调度器

    --local-scheduler一般用在开发阶段,这在一个产品中是不建议这样使用的.使用中央调度器有两个目的: 保证两个相同的task不会同时运行两次 提供一个可视化的界面 注意:中央调度器并不会帮 ...

  4. luigi学习7--running from command line

    最简单去运行一个luigi task的方式是通过luigi命令行工具. 示例代码: # my_module.py, available in your sys.path import luigi cl ...

  5. luigi学习6--parameters详解

    parameter就好比是一个task的构造方法.luigi要求你在类的scope上定义parameter. 如下面就是一个定义parameter的例子: class DailyReport(luig ...

  6. luigi学习5-task详解

    task是代码执行的地方.task通过target互相依赖. 下面是一个典型的task的大纲视图. 一.Task.requires requires方法用来指定本task的依赖的其他task对象,依赖 ...

  7. luigi学习4-构建工作流

    luigi提供了两个基本单元来构造一个工作流,这两个基本单元分别是Task和Target.这两个单元都是抽象类,我们实现他们中的某些方法就可以了.除了这两个基本单元,还有一个重要的概念是Pramete ...

  8. luigi学习-luigi的配置文件

    一.luigi配置文件的加载顺序 /etc/luigi/client.cfg luigi.cfg LUIGI_CONFIG_PATH环境变量 二.配置文件分节 配置文件被分为了多个section,每一 ...

  9. luigi学习2-在hadoop上运行Top Artists

    一.AggregateArtistsHadoop class AggregateArtistsHadoop(luigi.contrib.hadoop.JobTask): date_interval = ...

  10. luigi学习1

    一.luigi介绍 luigi是基于python语言的,可帮助建立复杂流式批处理任务管理系统.这些批处理作业典型的有hadoop job,数据库数据的导入与导出,或者是机器学习算法等等. luigi的 ...

随机推荐

  1. python笔记13-文件读写

    1.打开文件 f=open('a.txt','a+',encoding='utf-8')#f代表的是文件对象,叫句柄 f.seek(0)把文件指针到最前 文件打开模式有3种: 1:w写模式,它是不能读 ...

  2. 周强201771010141《面向对象程序设计(java)》第六周学习总结

    枚举是一种特殊的数据类型,之所以特殊是因为它既是一种类(class)类型却又比类型多了些特殊的约束,但是这些约束的存在也造就了枚举类型的简洁,安全性以及便捷性.创建枚举类型要使用enum关键字,隐含了 ...

  3. React-Native新列表组件FlatList和SectionList学习 | | 联动列表实现

    React-Native在0.43推出了两款新的列表组件:FlatList(高性能的简单列表组件)和SectionList(高性能的分组列表组件). 从官方上它们都支持常用的以下功能: 完全跨平台. ...

  4. TensorFlow安装教程---windows8.1

    首先,第一个,下载,python3.6.4版本 64位 安装python,由于,我是window8.1,所以我遇到这样的问题 参考解决方案:https://answers.microsoft.com/ ...

  5. iOS 证书申请和使用详解(详细版)阅读

    对于iOS开发者来说,apple开发者账号肯定不会陌生.在开发中我们离不开它.下面我简单的为大家分享一下关于iOS开发中所用的证书相关知识. 第一部分:成员介绍 1.Certification(证书) ...

  6. [转]Golang TLS

    首先是自签证书: openssl与数字证书的使用 https://blog.csdn.net/yue7603835/article/details/72569012 Golang TLS服务端/客户端 ...

  7. Centos6.5搭建Elasticsearch

    ElasticSearch是基于Lucene的搜索服务.支持分布式多用户能力的全文搜索引擎,提供RESTful web接口.Elasticsearch是用Java开发的,Apache旗下开源项目,支持 ...

  8. CentOS6.5安装mysql5.7

    CentOS6.5安装mysql5.7 查看mysql的安装路径: [root@bogon ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib/mysql ...

  9. 公众号及H5支付

    本篇主要记录微信支付中公众号及H5支付全过程. 1|1准备篇 公众号或者服务号(并开通微信支付功能).商户平台中开通JSAPI支付.H5支付. 1|2配置篇 公众号或者服务号中 -------开发-- ...

  10. 【自动化测试:笔记一】adb命令

    1.查看当前连接的设备数 adb devices 2.连接设备 adb connect <设备名> 3.安装卸载app adb install packagesname adb unins ...