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

Persist and enrich job results #26

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions ecospheres_migrator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

app = Flask(__name__)
app.config["SECRET_KEY"] = os.getenv("FLASK_SECRET_KEY", "default-secret-key")
app.config["TRANSFORM_TTL"] = 60 * 60 * 24 * 7 # 1 week
app.config["MIGRATE_TTL"] = 60 * 60 * 24 * 7 * 30 # 1 month


@app.route("/")
Expand Down Expand Up @@ -96,7 +98,9 @@ def transform():
abort(400, "Missing `transformation` parameter")
migrator = Migrator(url=url, username=username, password=password)
selection = migrator.select(query=query)
job = get_queue().enqueue(migrator.transform, transformation, selection)
job = get_queue().enqueue(
migrator.transform, transformation, selection, result_ttl=app.config["TRANSFORM_TTL"]
)
return redirect(url_for("transform_success", job_id=job.id))


Expand Down Expand Up @@ -160,7 +164,11 @@ def migrate(job_id: str):
abort(400, "Missing `group` parameter")
migrator = Migrator(url=url, username=username, password=password)
migrate_job = get_queue().enqueue(
migrator.migrate, transform_job.result, overwrite=overwrite, group=group
migrator.migrate,
transform_job.result,
overwrite=overwrite,
group=group,
result_ttl=app.config["MIGRATE_TTL"],
)
return redirect(url_for("migrate_success", job_id=migrate_job.id))

Expand Down
2 changes: 2 additions & 0 deletions ecospheres_migrator/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BatchRecord:
uuid: str
template: bool
original: str
url: str


@dataclass(kw_only=True)
Expand Down Expand Up @@ -49,6 +50,7 @@ class MigrateBatchRecord:
source_content: str
target_content: str
template: bool
url: str


@dataclass(kw_only=True)
Expand Down
5 changes: 5 additions & 0 deletions ecospheres_migrator/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def transform(self, transformation: Path, selection: list[Record]) -> Batch:
# TODO: check if result != original
batch.add(
SuccessBatchRecord(
url=self.gn.url,
uuid=r.uuid,
template=r.template,
original=xml_to_string(original),
Expand All @@ -77,6 +78,7 @@ def transform(self, transformation: Path, selection: list[Record]) -> Batch:
except Exception as e:
batch.add(
FailureBatchRecord(
url=self.gn.url,
uuid=r.uuid,
template=r.template,
original=xml_to_string(original),
Expand All @@ -100,6 +102,7 @@ def migrate(
self.gn.update_record(r.uuid, r.result, template=r.template)
migrate_batch.add(
SuccessMigrateBatchRecord(
url=self.gn.url,
source_uuid=r.uuid,
target_uuid=r.uuid,
template=r.template,
Expand All @@ -115,6 +118,7 @@ def migrate(
)
migrate_batch.add(
SuccessMigrateBatchRecord(
url=self.gn.url,
source_uuid=r.uuid,
target_uuid=new_record["uuid"],
template=r.template,
Expand All @@ -125,6 +129,7 @@ def migrate(
except Exception as e:
migrate_batch.add(
FailureMigrateBatchRecord(
url=self.gn.url,
source_uuid=r.uuid,
template=r.template,
source_content=r.original,
Expand Down
Loading