当前位置: 首页 > news >正文

luigi 学习

luigi 学习

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(1000):

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

                    random.randint(0, 999),

                    random.randint(0, 999),

                    random.randint(0, 999)))

 

    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] += 1

        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循环来读取

posted on 2018-10-25 13:10 potatoknight 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/longjmp/p/9849175.html

相关文章:

  • oracle的substr函数的用法
  • 博客索引
  • 刚登录,有点感觉就想写下来
  • ubuntu 14.04 添加、删除用户,修改用户名称,修改主机名
  • 本博客迁移到 http://www.cleocn.com , 该站使用SharePoint 2007 Blog模板架设
  • CURL POST 请求
  • 《WF编程》系列之9 - 编译工作流:使用WFC.EXE
  • 【TPShop】首页商品楼层
  • 迅雷最新版本存在严重的远程拒绝服务漏洞(0day)
  • cas配置不通过登陆校验的页面
  • [VJ]输出m/n,若是循环体只输出第一节
  • 删除顽固文件十二招
  • 如何将SLIC集成到ESXi中
  • MSSQL2005注入攻击(测试兰州电信)
  • bootstrap-table 的必备参数
  • 【159天】尚学堂高琪Java300集视频精华笔记(128)
  • CentOS从零开始部署Nodejs项目
  • css选择器
  • Debian下无root权限使用Python访问Oracle
  • Flannel解读
  • magento2项目上线注意事项
  • php ci框架整合银盛支付
  • Ruby 2.x 源代码分析:扩展 概述
  • V4L2视频输入框架概述
  • 前端
  • 浅谈web中前端模板引擎的使用
  • 赢得Docker挑战最佳实践
  • 怎样选择前端框架
  • 智能网联汽车信息安全
  • 400多位云计算专家和开发者,加入了同一个组织 ...
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • ​比特币大跌的 2 个原因
  • !!【OpenCV学习】计算两幅图像的重叠区域
  • #LLM入门|Prompt#3.3_存储_Memory
  • (Redis使用系列) Springboot 实现Redis消息的订阅与分布 四
  • (初研) Sentence-embedding fine-tune notebook
  • (顺序)容器的好伴侣 --- 容器适配器
  • (已解决)vue+element-ui实现个人中心,仿照原神
  • (原創) 如何安裝Linux版本的Quartus II? (SOC) (Quartus II) (Linux) (RedHat) (VirtualBox)
  • .net core webapi 大文件上传到wwwroot文件夹
  • .net core 调用c dll_用C++生成一个简单的DLL文件VS2008
  • .net core 依赖注入的基本用发
  • .NET Project Open Day(2011.11.13)
  • .Net(C#)自定义WinForm控件之小结篇
  • [BIZ] - 1.金融交易系统特点
  • [CareerCup] 2.1 Remove Duplicates from Unsorted List 移除无序链表中的重复项
  • [hdu 2826] The troubles of lmy [简单计算几何 - 相似]
  • [iOS]让Xcode 4.2生成的app支持老的iOS设备(armv6)
  • [leetcode] Balanced Binary Tree
  • [Neural Network] {Université de Sherbrooke} L2.9 Param Initialization
  • [Python学习]总结一下Cygwin安装与进阶学习列表
  • [Qualcomm][Power]QCM2290功耗异常问题
  • [SPOJ]COT2
  • [Spring] Spring Boot 生态
  • [STM32F407ZET6] GPIO