Skip to content

Commit

Permalink
alembic: change jobs table names for consistency
Browse files Browse the repository at this point in the history
* tests: adapt tests to new implementation of jobs registry
* chore: fix formatting
  • Loading branch information
kpsherva committed Aug 26, 2024
1 parent 03de8c4 commit 9b78b9d
Show file tree
Hide file tree
Showing 31 changed files with 323 additions and 349 deletions.
2 changes: 2 additions & 0 deletions invenio_jobs/administration/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_api_endpoint(self, pid_value=None):
return f"/api/jobs/{pid_value}/runs"

def get_details_api_endpoint(self):
"""Compute api endpoint link for job details view."""
api_url_prefix = current_app.config["SITE_API_URL"]
slash_tpl = "/" if not self.api_endpoint.startswith("/") else ""

Expand All @@ -117,6 +118,7 @@ def get_details_api_endpoint(self):
return f"{slash_tpl}{self.api_endpoint}"

def get_context(self, **kwargs):
"""Compute admin view context."""
ctx = super().get_context(**kwargs)
ctx["request_headers"] = self.request_headers
ctx["ui_config"] = self.item_field_list
Expand Down
9 changes: 0 additions & 9 deletions invenio_jobs/administration/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,3 @@ class RunsListView(AdminResourceListView):
display_edit = False
display_create = False
actions = None

# item_field_list = {
# "job": {"text": _("Jobs"), "order": 1, "width": 3},
# "active": {"text": _("Status"), "order": 2, "width": 2},
# "last_run_start_time": {"text": _("Last run"), "order": 3, "width": 3},
# "user": {"text": _("Started by"), "order": 4, "width": 3},
# "next_run": {"text": _("Next run"), "order": 5, "width": 3},
# }

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2018 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Update jobs module table names."""

import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "1f896f6990b8"
down_revision = "356496a01197"
branch_labels = ()
depends_on = None


def upgrade():
"""Upgrade database."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_run_job_id_job", "run", type_="foreignkey")
op.rename_table("job", "jobs_job")
op.rename_table("run", "jobs_run")

op.create_foreign_key(
"fk_jobs_run_job_id_jobs_job", "jobs_run", "jobs_job", ["job_id"], ["id"]
)
op.drop_column("jobs_job", "default_args")

# ### end Alembic commands ###


def downgrade():
"""Downgrade database."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint("fk_jobs_run_job_id_jobs_job", "jobs_run", type_="foreignkey")

op.rename_table("jobs_job", "job")
op.rename_table("jobs_run", "run")
op.create_foreign_key("fk_run_job_id_job", "run", "job", ["job_id"], ["id"])
op.add_column(
"job",
sa.Column(
"default_args",
sa.JSON()
.with_variant(sqlalchemy_utils.types.json.JSONType(), "mysql")
.with_variant(
postgresql.JSONB(none_as_null=True, astext_type=sa.Text()), "postgresql"
)
.with_variant(sqlalchemy_utils.types.json.JSONType(), "sqlite"),
nullable=True,
),
)

# ### end Alembic commands ###
17 changes: 17 additions & 0 deletions invenio_jobs/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# Invenio-Jobs is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Record class mock."""


class AttrDict(dict):
"""Mock record class."""

def __init__(self, *args, **kwargs):
"""Constructor."""
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";
import { Button, Modal, Icon } from "semantic-ui-react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import { i18next } from "@translations/invenio_app_rdm/i18next";
import _isEmpty from "lodash/isEmpty";
import PropTypes from "prop-types";
import React, { Component } from "react";
import { http } from "react-invenio-forms";
import { Divider, Button, Grid, Header } from "semantic-ui-react";
import { AdminUIRoutes } from "@js/invenio_administration";
import { withCancel } from "react-invenio-forms";

export class JobRunsHeader extends Component {
constructor(props) {
Expand Down Expand Up @@ -45,17 +43,13 @@ export class JobRunsHeader extends Component {

render() {
const {
pid,
columns,
actions,
apiEndpoint,
idKeyPath,
listUIEndpoint,
resourceSchema,
resourceName,
displayDelete,
displayEdit,
uiSchema,
data,
error,
loading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { UserListItemCompact, toRelativeTime } from "react-invenio-forms";
import { withState } from "react-searchkit";
import { Popup, Table, Button } from "semantic-ui-react";
import { Actions } from "@js/invenio_administration";
import { RunButton } from "./RunButton";
import { StatusFormatter } from "./StatusFormatter";
import { AdminUIRoutes } from "@js/invenio_administration/src/routes";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React, { Component } from "react";
import PropTypes from "prop-types";
import { ActionFormLayout } from "@js/invenio_administration";
import ReactJson from "react-json-view";
import ReactJson from "@microlink/react-json-view";
import { Accordion, Icon, Modal } from "semantic-ui-react";

export class RunActionForm extends Component {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SearchResultItemComponent extends Component {
render() {
const { result } = this.props;
const { status } = this.state;
debugger; // eslint-disable-line no-debugger
return (
<Table.Row>
<Table.Cell
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React from "react";
import PropTypes from "prop-types";
import { Modal, Dropdown, Input, Button, Icon } from "semantic-ui-react";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN
//
// Invenio RDM Records is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import { BoolFormatter } from "@js/invenio_administration";
import { i18next } from "@translations/invenio_app_rdm/i18next";
import React from "react";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { initDefaultSearchComponents } from "@js/invenio_administration";
import { createSearchAppInit } from "@js/invenio_search_ui";
import { NotificationController } from "@js/invenio_administration";
import { JobRunsHeader } from "./JobRunsHeader";
import { RunActionForm } from "./RunActionForm";
import { SearchResultItemLayout } from "./JobSearchResultItemLayout";
import { JobSearchLayout } from "./JobSearchLayout";
Expand Down
1 change: 0 additions & 1 deletion invenio_jobs/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def jobs(self):
return self.registry.all_registered_jobs()



def finalize_app(app):
"""Finalize app."""
rr_ext = app.extensions["invenio-records-resources"]
Expand Down
10 changes: 9 additions & 1 deletion invenio_jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
#
# Invenio-Jobs is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Jobs module."""

from functools import partial


class RegisteredTask:
"""Base class to register tasks available in the admin panel."""

arguments_schema = None
task = None
id = None
title = None
description = None

@classmethod
def factory(cls, job_cls_name, arguments_schema, id_, task, description, title, attrs=None):
def factory(
cls, job_cls_name, arguments_schema, id_, task, description, title, attrs=None
):
"""Create a new instance of a job."""
if not attrs:
attrs = {}
Expand All @@ -34,6 +41,7 @@ def factory(cls, job_cls_name, arguments_schema, id_, task, description, title,

@classmethod
def build_task_arguments(cls, job_obj, since=None, custom_args=None, **kwargs):
"""Build task arguments."""
if custom_args:
return custom_args
return {}
Loading

0 comments on commit 9b78b9d

Please sign in to comment.