Skip to content
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
6 changes: 5 additions & 1 deletion actur/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time

import feedparser
import sentry_sdk

from actur.config import readconf as rc
from actur.utils import dbif, feeds, hasher
Expand Down Expand Up @@ -71,7 +72,8 @@ def process_feed(
global _logger
bump_processed, bump_added, bump_skipped, get_counts = pcounters()
feedname = feed.name
print("feedname", feedname)
if not silent:
print("feedname", feedname)
url = feed.url
d = feedparser.parse(url)
if not silent:
Expand Down Expand Up @@ -109,6 +111,7 @@ def process_feed(
# print(f"title {title} classified as {category}")
except Exception as e:
msg = f"Classifier exception on title {title}: {e}"
sentry_sdk.capture_message(msg)
if not silent:
print(msg)
if not no_logging:
Expand Down Expand Up @@ -152,6 +155,7 @@ def process_pubs(xgroup: str | None, silent: bool, no_logging: bool, categorize:
parse_pub(pub, silent, categorize, no_logging)
except Exception as e:
msg = f"Could not read {pub.name}: {e}"
sentry_sdk.capture_message(msg)
if not silent:
print(msg)
if not no_logging:
Expand Down
10 changes: 10 additions & 0 deletions actur/sentry_div.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sentry_sdk
from config import readconf as rc

dsn = rc.get_conf_by_key("sentry")["dsn"]

sentry_sdk.init(
dsn=rc.get_conf_by_key("sentry")["dsn"],
)

div_by_zero = 1 / 0
38 changes: 38 additions & 0 deletions actur/sentry_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sentry_sdk
import sentry_sdk.profiler
from config import readconf as rc


sentry_sdk.init(
dsn=rc.get_conf_by_key("sentry")["dsn"],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
)


def slow_function():
import time

time.sleep(0.1)
return "done"


def fast_function():
import time

time.sleep(0.05)
return "done"


# Manually call start_profiler and stop_profiler
# to profile the code in between
sentry_sdk.profiler.start_profiler()
for i in range(0, 10):
slow_function()
fast_function()
#
# Calls to stop_profiler are optional -
# if you don't stop the profiler, it will keep profiling
# your application until the process exits or stop_profiler is called.
sentry_sdk.profiler.stop_profiler()
35 changes: 25 additions & 10 deletions actur/utils/dbif.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
import pymongo
from bson.json_util import dumps, RELAXED_JSON_OPTIONS
from actur.config import readconf as rc
import sentry_sdk

sentry_sample_rate = rc.get_conf_by_key("sentry")["sample_rate"]
sentry_sdk.init(
dsn=rc.get_conf_by_key("sentry")["dsn"],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=sentry_sample_rate,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=sentry_sample_rate,
)

_host: str | None = None
_client: pymongo.MongoClient
Expand Down Expand Up @@ -37,8 +50,9 @@ def _init_db():


def save_article(entry):
db = get_db()
db.articles.insert_one(entry)
with sentry_sdk.start_transaction(op="save_article"):
db = get_db()
db.articles.insert_one(entry)


def get_article_count() -> int:
Expand All @@ -47,14 +61,15 @@ def get_article_count() -> int:


def is_summary_in_db(target_hash, summary):
db = get_db()
articles_with_target_hash = db.articles.find({"hash": target_hash})
for article in articles_with_target_hash:
if article["summary"] == summary:
return True
else:
continue
return False
with sentry_sdk.start_transaction(op="is_summary_in_db"):
db = get_db()
articles_with_target_hash = db.articles.find({"hash": target_hash})
for article in articles_with_target_hash:
if article["summary"] == summary:
return True
else:
continue
return False


def find_text(collname: str, search_text: str):
Expand Down
7 changes: 3 additions & 4 deletions notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

pytest --cov=actur tests/


## proposed signal handler

```python
Expand Down Expand Up @@ -75,14 +74,14 @@ For display to work, must export ACTUCONF=$HOME/.actur/local.toml (this is now t

Copy sup-actur.conf to /etc/supervisor/conf.d/actur.conf

and restart supervisor supervisorctl start actur-local [or start all if actuproxy being used]
and restart supervisor supervisorctl start actur-local [or start all if actuproxy being used]

New openai interface:

https://github.com/openai/openai-python/discussions/742
discussion
discussion [https://github.com/openai/openai-python/discussions/742]

## commands

actu read --categorize [--silent] [-d]

actu show -h 3 all
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/agoldhammer/actur",
version="0.1.0",
version="0.2.2",
zip_safe=False,
)