当前位置: 首页>>代码示例>>Python>>正文


Python JobItem.workTypes方法代码示例

本文整理汇总了Python中twext.enterprise.jobs.jobitem.JobItem.workTypes方法的典型用法代码示例。如果您正苦于以下问题:Python JobItem.workTypes方法的具体用法?Python JobItem.workTypes怎么用?Python JobItem.workTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twext.enterprise.jobs.jobitem.JobItem的用法示例。


在下文中一共展示了JobItem.workTypes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: poll

# 需要导入模块: from twext.enterprise.jobs.jobitem import JobItem [as 别名]
# 或者: from twext.enterprise.jobs.jobitem.JobItem import workTypes [as 别名]
    def poll(self):
        if self._polling:
            return

        self._polling = True

        txn = self._store.newTransaction()
        try:

            # Look up all of the jobs

            events = []

            jobsByTypeName = {}

            for job in (yield JobItem.all(txn)):
                jobsByTypeName.setdefault(job.workType, []).append(job)

            totalsByTypeName = {}

            for workType in JobItem.workTypes():
                typeName = workType.table.model.name
                jobs = jobsByTypeName.get(typeName, [])
                totalsByTypeName[typeName] = len(jobs)

                jobDicts = []

                for job in jobs:
                    def formatTime(datetime):
                        if datetime is None:
                            return None
                        else:
                            # FIXME: Use HTTP time format
                            return datetime.ctime()

                    jobDict = dict(
                        job_jobID=job.jobID,
                        job_priority=job.priority,
                        job_weight=job.weight,
                        job_notBefore=formatTime(job.notBefore),
                    )

                    work = yield job.workItem()

                    attrs = ("workID", "group")

                    if workType == PushNotificationWork:
                        attrs += ("pushID", "priority")
                    elif workType == ScheduleOrganizerWork:
                        attrs += ("icalendarUID", "attendeeCount")
                    elif workType == ScheduleRefreshWork:
                        attrs += ("icalendarUID", "attendeeCount")
                    elif workType == ScheduleReplyWork:
                        attrs += ("icalendarUID",)
                    elif workType == ScheduleAutoReplyWork:
                        attrs += ("icalendarUID",)
                    elif workType == GroupCacherPollingWork:
                        attrs += ()
                    elif workType == IMIPPollingWork:
                        attrs += ()
                    elif workType == IMIPReplyWork:
                        attrs += ("organizer", "attendee")
                    else:
                        attrs = ()

                    if attrs:
                        if work is None:
                            self.log.error(
                                "workItem() returned None for job: {job}",
                                job=job
                            )
                            # jobDict.update((attr, None) for attr in attrs)
                            for attr in attrs:
                                jobDict["work_{}".format(attr)] = None
                        else:
                            # jobDict.update(
                            #     ("work_{}".format(attr), getattr(work, attr))
                            #     for attr in attrs
                            # )
                            for attr in attrs:
                                jobDict["work_{}".format(attr)] = (
                                    getattr(work, attr)
                                )

                    jobDicts.append(jobDict)

                if jobDicts:
                    events.append(dict(
                        eventClass=typeName,
                        eventID=time(),
                        eventText=asJSON(jobDicts),
                    ))

            events.append(dict(
                eventClass=u"work-total",
                eventID=time(),
                eventText=asJSON(totalsByTypeName),
                eventRetry=(self._pollInterval),
            ))

#.........这里部分代码省略.........
开发者ID:eventable,项目名称:CalendarServer,代码行数:103,代码来源:work.py


注:本文中的twext.enterprise.jobs.jobitem.JobItem.workTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。