Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicitly add handler to function using a partial #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ from py_agent.jobs import github_notifications
from py_agent.listeners import add_issue_to_todoist, add_pr_to_todoist

agent = Agent()
task = agent.create_partial(github_notifications)

agent.schedule.every(10).seconds.do(github_notifications, handler=agent.handler)
agent.schedule.every(10).seconds.do(task)

agent.add_listener(add_issue_to_todoist, {'event_type': ('==', 'new_issue_assigned')})
agent.add_listener(add_pr_to_todoist, {'event_type': ('==', 'new_pr_review')})
Expand Down
4 changes: 4 additions & 0 deletions src/py_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from py_agent.db import init_db
from py_agent.event_handler import EventHandler

from functools import partial

logging.basicConfig(level=logging.INFO)


Expand Down Expand Up @@ -35,3 +37,5 @@ def go(self):
except Exception:
logging.error("Job failed", exc_info=True)

def create_partial(self, task):
return partial(task, handler=self.handler)