Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/dsw-data-seeder/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed error reporting on worker startup


## [4.14.0]

Expand Down
16 changes: 13 additions & 3 deletions packages/dsw-data-seeder/dsw/data_seeder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .config import SeederConfig, SeederConfigParser
from .consts import (PROG_NAME, VERSION, NULL_UUID, DEFAULT_ENCODING,
VAR_SEEDER_RECIPE, VAR_WORKDIR_PATH, VAR_APP_CONFIG_PATH)
from .seeder import DataSeeder, SeedRecipe
from .seeder import DataSeeder, SeedRecipe, SentryReporter


def load_config_str(config_str: str) -> SeederConfig:
Expand Down Expand Up @@ -61,7 +61,12 @@ def run(ctx: click.Context, recipe: str):
cfg = ctx.obj['cfg']
workdir = ctx.obj['workdir']
seeder = DataSeeder(cfg=cfg, workdir=workdir)
seeder.run(recipe)
try:
seeder.run(recipe)
except Exception as e:
click.echo(f'Error: {e}', err=True)
SentryReporter.capture_exception(e)
sys.exit(2)


@cli.command(name='seed', help='Seed data directly.')
Expand All @@ -72,7 +77,12 @@ def seed(ctx: click.Context, recipe: str, tenant_uuid: str):
cfg = ctx.obj['cfg']
workdir = ctx.obj['workdir']
seeder = DataSeeder(cfg=cfg, workdir=workdir)
seeder.seed(recipe_name=recipe, tenant_uuid=tenant_uuid)
try:
seeder.seed(recipe_name=recipe, tenant_uuid=tenant_uuid)
except Exception as e:
click.echo(f'Error: {e}', err=True)
SentryReporter.capture_exception(e)
sys.exit(2)


@cli.command(name='list', help='List recipes for data seeding.')
Expand Down
10 changes: 7 additions & 3 deletions packages/dsw-data-seeder/dsw/data_seeder/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .cli import load_config_str
from .consts import (VAR_APP_CONFIG_PATH, VAR_WORKDIR_PATH,
VAR_SEEDER_RECIPE, DEFAULT_ENCODING)
from .seeder import DataSeeder
from .seeder import DataSeeder, SentryReporter


# pylint: disable-next=unused-argument
Expand All @@ -19,5 +19,9 @@ def lambda_handler(event, context):
sys.exit(1)

config = load_config_str(config_path.read_text(encoding=DEFAULT_ENCODING))
seeder = DataSeeder(config, workdir_path)
seeder.run_once(recipe_name)
try:
seeder = DataSeeder(config, workdir_path)
seeder.run_once(recipe_name)
except Exception as e:
SentryReporter.capture_exception(e)
raise e
5 changes: 4 additions & 1 deletion packages/dsw-data-seeder/dsw/data_seeder/seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ def __init__(self, cfg: SeederConfig, workdir: pathlib.Path):
self.cfg = cfg
self.workdir = workdir
self.recipe = SeedRecipe.create_default() # type: SeedRecipe
self.dbs = {} # type: dict[str, Database]

self._init_context(workdir=workdir)
self.dbs = {} # type: dict[str, Database]
self._init_sentry()
self._init_extra_connections()

def _init_context(self, workdir: pathlib.Path):
Expand All @@ -228,6 +229,8 @@ def _init_context(self, workdir: pathlib.Path):
multi_tenant=self.cfg.cloud.multi_tenant,
),
)

def _init_sentry(self):
SentryReporter.initialize(
config=self.cfg.sentry,
release=BUILD_INFO.version,
Expand Down
4 changes: 4 additions & 0 deletions packages/dsw-document-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed error reporting on worker startup


## [4.14.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/dsw-document-worker/dsw/document_worker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ def main(config: DocumentWorkerConfig, workdir: str):
worker.run()
except Exception as e:
SentryReporter.capture_exception(e)
click.echo(f'Ended with error: {e}')
click.echo(f'Error: {e}', err=True)
sys.exit(2)
10 changes: 7 additions & 3 deletions packages/dsw-document-worker/dsw/document_worker/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .cli import load_config_str
from .consts import VAR_APP_CONFIG_PATH, VAR_WORKDIR_PATH, DEFAULT_ENCODING
from .worker import DocumentWorker
from .worker import DocumentWorker, SentryReporter


# pylint: disable-next=unused-argument
Expand All @@ -12,5 +12,9 @@ def lambda_handler(event, context):
workdir_path = pathlib.Path(os.getenv(VAR_WORKDIR_PATH, '/var/task/templates'))

config = load_config_str(config_path.read_text(encoding=DEFAULT_ENCODING))
doc_worker = DocumentWorker(config, workdir_path)
doc_worker.run_once()
try:
doc_worker = DocumentWorker(config, workdir_path)
doc_worker.run_once()
except Exception as e:
SentryReporter.capture_exception(e)
raise e
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,11 @@ class DocumentWorker(CommandWorker):

def __init__(self, config: DocumentWorkerConfig, workdir: pathlib.Path):
self.config = config
self._init_context(workdir=workdir)
self.current_job: Job | None = None

self._init_context(workdir=workdir)
self._init_sentry()

def _init_context(self, workdir: pathlib.Path):
Context.initialize(
config=self.config,
Expand Down
4 changes: 4 additions & 0 deletions packages/dsw-mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed error reporting on worker startup


## [4.14.0]

Expand Down
16 changes: 13 additions & 3 deletions packages/dsw-mailer/dsw/mailer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .config import MailerConfig, MailerConfigParser
from .consts import (VERSION, VAR_APP_CONFIG_PATH, VAR_WORKDIR_PATH,
DEFAULT_ENCODING)
from .mailer import Mailer
from .mailer import Mailer, SentryReporter
from .model import MessageRequest


Expand Down Expand Up @@ -77,14 +77,24 @@ def cli(ctx, config: MailerConfig, workdir: str):
type=click.File('r', encoding=DEFAULT_ENCODING))
def send(ctx, msg_request: MessageRequest, config: MailerConfig):
mailer: Mailer = ctx.obj['mailer']
mailer.send(rq=msg_request, cfg=config.mail)
try:
mailer.send(rq=msg_request, cfg=config.mail)
except Exception as e:
SentryReporter.capture_exception(e)
click.echo(f'Error: {e}', err=True)
sys.exit(2)


@cli.command(name='run', help='Run mailer worker processing message jobs.')
@click.pass_context
def run(ctx):
mailer: Mailer = ctx.obj['mailer']
mailer.run()
try:
mailer.run()
except Exception as e:
SentryReporter.capture_exception(e)
click.echo(f'Error: {e}', err=True)
sys.exit(2)


def main():
Expand Down
10 changes: 7 additions & 3 deletions packages/dsw-mailer/dsw/mailer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .cli import load_config_str
from .consts import VAR_APP_CONFIG_PATH, VAR_WORKDIR_PATH, DEFAULT_ENCODING
from .mailer import Mailer
from .mailer import Mailer, SentryReporter


# pylint: disable-next=unused-argument
Expand All @@ -12,5 +12,9 @@ def lambda_handler(event, context):
workdir_path = pathlib.Path(os.getenv(VAR_WORKDIR_PATH, '/var/task/templates'))

config = load_config_str(config_path.read_text(encoding=DEFAULT_ENCODING))
mailer = Mailer(config, workdir_path)
mailer.run_once()
try:
mailer = Mailer(config, workdir_path)
mailer.run_once()
except Exception as e:
SentryReporter.capture_exception(e)
raise e
3 changes: 3 additions & 0 deletions packages/dsw-mailer/dsw/mailer/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, cfg: MailerConfig, workdir: pathlib.Path):
)

self._init_context(workdir=workdir)
self._init_sentry()
self.ctx = Context.get()

def _init_context(self, workdir: pathlib.Path):
Expand All @@ -44,6 +45,8 @@ def _init_context(self, workdir: pathlib.Path):
workdir=workdir,
db=Database(cfg=self.cfg.db, connect=False),
)

def _init_sentry(self):
SentryReporter.initialize(
config=self.cfg.sentry,
release=BUILD_INFO.version,
Expand Down
Loading