-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
75 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# avoid circular import | ||
# from Products.EasyNewsletter import config # noqa | ||
import logging | ||
import threading | ||
|
||
from huey.bin.huey_consumer import load_huey | ||
from huey.consumer_options import ConsumerConfig | ||
from zope.i18nmessageid import MessageFactory | ||
import logging | ||
|
||
log = logging.getLogger("Products.EasyNewsletter") | ||
|
||
EasyNewsletterMessageFactory = MessageFactory("Products.EasyNewsletter") | ||
_ = EasyNewsletterMessageFactory | ||
|
||
consumer_options = { | ||
"backoff": 1.15, | ||
"check_worker_health": True, | ||
"extra_locks": None, | ||
"flush_locks": False, | ||
"health_check_interval": 10, | ||
"initial_delay": 0.1, | ||
"max_delay": 10.0, | ||
"periodic": True, | ||
"scheduler_interval": 1, | ||
"worker_type": "thread", | ||
"workers": 1, | ||
"logfile": "huey.log", | ||
"verbose": False, | ||
} | ||
|
||
h = load_huey("Products.EasyNewsletter.queue.huey.huey_tasks.huey") | ||
|
||
cconfig = ConsumerConfig(**consumer_options) | ||
cconfig.validate() | ||
cconfig.setup_logger() | ||
cconsumer = h.create_consumer(**cconfig.values) | ||
|
||
th = threading.Thread(target=cconsumer.run) | ||
th.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
from collective.taskqueue import taskqueue | ||
from plone import api | ||
from collective.taskqueue2.huey_tasks import schedule_browser_view | ||
from Products.EasyNewsletter.queue.interfaces import IIssueQueue | ||
from zope.interface import implementer | ||
|
||
|
||
QUEUE_NAME = "Products.EasyNewsletter.queue" | ||
VIEW_NAME = "enl_taskqueue_sendout" | ||
ENL_VIEW_NAME = "enl_taskqueue_sendout" | ||
|
||
|
||
@implementer(IIssueQueue) | ||
class TCIssueQueue(object): | ||
def start(self, context): | ||
"""Queues issue for sendout through collective.taskqueue""" | ||
jobid = taskqueue.add( | ||
"/".join(context.getPhysicalPath() + (VIEW_NAME,)), queue=QUEUE_NAME | ||
# import pdb; pdb.set_trace() # NOQA: E702 | ||
result = schedule_browser_view( | ||
view_name=ENL_VIEW_NAME, | ||
context_path="/".join(context.getPhysicalPath()), | ||
site_path="/".join(api.portal.get().getPhysicalPath()), | ||
username=api.user.get_current().getId(), | ||
params=dict( | ||
base=context.REQUEST.base, | ||
layers=context.REQUEST.__provides__, | ||
cookies=context.REQUEST.cookies, | ||
form=dict(), | ||
_plonebrowserlayer_=context.REQUEST._plonebrowserlayer_, | ||
_plonetheme_=context.REQUEST._plonetheme_, | ||
), | ||
) | ||
return jobid | ||
# jobid = taskqueue.add( | ||
# "/".join(context.getPhysicalPath() + (VIEW_NAME,)), queue=QUEUE_NAME | ||
# ) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone import api | ||
from plone.protect.interfaces import IDisableCSRFProtection | ||
from Products.Five.browser import BrowserView | ||
from zope.interface import alsoProvides | ||
|
||
from Products.EasyNewsletter import log | ||
|
||
|
||
class ProcessQueue(BrowserView): | ||
def __call__(self): | ||
alsoProvides(self.request, IDisableCSRFProtection) | ||
self.context.send() | ||
log.info("start sending:\n") | ||
import pdb; pdb.set_trace() # NOQA: E702`c` | ||
# send_view = api.content.get_view(name="send-issue", context=self.context) | ||
send_view = self.context.restrictedTraverse("send-issue") | ||
send_view.send() | ||
log.info("sending done ;)\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters