Module libnova.common.api.Job

Expand source code
#!/usr/bin/env python
# coding: utf-8

import datetime
from enum import Enum
from libnova.common import api

# Define Enum structs
from libnova.common.api.Serializable import Serializable


class JobStatus(Enum):
    """Job Status
    """
    RUNNING   = 1
    COMPLETED = 2
    WAITING   = 3
    FAILED    = 4


class JobResult(Enum):
    """Job Result
    """
    OK              = 1
    OK_WITH_WARNING = 2
    ERROR           = 3


# Define main object structure
class Job(Serializable):
    """Job

    The main methods allows the interaction with the main structures related to jobs hosted in the platform
    """

    id:              int       = 0
    user_id:         int
    function_id:     int
    container_id:    int
    file_id:         int
    status:          JobStatus = 3
    result:          JobResult = 1
    last_heart_beat: datetime.datetime
    start_date:      datetime.datetime
    end_date:        datetime.datetime
    function_input:  str

#Define main functions as "static"


def create() -> Job:
    """Create a new job

    Returns:
        Job: A new `Job`
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.post(
            url_segment='job'
        ),
        Job
    )


def get(id) -> Job:
    """Get an existing job

    Args:
        id: The id of the `Job` to retrieve

    Returns:
        Job: An existing `Job` if exists, None otherwise
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.get(
            url_segment='job/' + str(id)
        ),
        Job
    )


def set_status(job_id, status: JobStatus):
    """Update a job with a given `status`

    Args:
        job_id (int): The `Job` id
        status (str): The new `Job Status`

    Returns:
        Job: The updated `Job`
    """

    query = {
        "status": status.name
    }

    api_driver = api.Driver.get_instance()
    return api_driver.put_json(
        url_segment='job/' + job_id,
        data=query
    )


if __name__ == "__main__":
    print('This file cannot be executed directly!')

Functions

def create() ‑> Job

Create a new job

Returns

Job
A new Job
Expand source code
def create() -> Job:
    """Create a new job

    Returns:
        Job: A new `Job`
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.post(
            url_segment='job'
        ),
        Job
    )
def get(id) ‑> Job

Get an existing job

Args

id
The id of the Job to retrieve

Returns

Job
An existing Job if exists, None otherwise
Expand source code
def get(id) -> Job:
    """Get an existing job

    Args:
        id: The id of the `Job` to retrieve

    Returns:
        Job: An existing `Job` if exists, None otherwise
    """

    api_driver = api.Driver.get_instance()

    return api_driver.serialize(
        api_driver.get(
            url_segment='job/' + str(id)
        ),
        Job
    )
def set_status(job_id, status: JobStatus)

Update a job with a given status

Args

job_id : int
The Job id
status : str
The new Job Status

Returns

Job
The updated Job
Expand source code
def set_status(job_id, status: JobStatus):
    """Update a job with a given `status`

    Args:
        job_id (int): The `Job` id
        status (str): The new `Job Status`

    Returns:
        Job: The updated `Job`
    """

    query = {
        "status": status.name
    }

    api_driver = api.Driver.get_instance()
    return api_driver.put_json(
        url_segment='job/' + job_id,
        data=query
    )

Classes

class Job (**entries: dict)

Job

The main methods allows the interaction with the main structures related to jobs hosted in the platform

Expand source code
class Job(Serializable):
    """Job

    The main methods allows the interaction with the main structures related to jobs hosted in the platform
    """

    id:              int       = 0
    user_id:         int
    function_id:     int
    container_id:    int
    file_id:         int
    status:          JobStatus = 3
    result:          JobResult = 1
    last_heart_beat: datetime.datetime
    start_date:      datetime.datetime
    end_date:        datetime.datetime
    function_input:  str

Ancestors

Class variables

var container_id : int
var end_date : datetime.datetime
var file_id : int
var function_id : int
var function_input : str
var id : int
var last_heart_beat : datetime.datetime
var resultJobResult
var start_date : datetime.datetime
var statusJobStatus
var user_id : int
class JobResult (value, names=None, *, module=None, qualname=None, type=None, start=1)

Job Result

Expand source code
class JobResult(Enum):
    """Job Result
    """
    OK              = 1
    OK_WITH_WARNING = 2
    ERROR           = 3

Ancestors

  • enum.Enum

Class variables

var ERROR
var OK
var OK_WITH_WARNING
class JobStatus (value, names=None, *, module=None, qualname=None, type=None, start=1)

Job Status

Expand source code
class JobStatus(Enum):
    """Job Status
    """
    RUNNING   = 1
    COMPLETED = 2
    WAITING   = 3
    FAILED    = 4

Ancestors

  • enum.Enum

Class variables

var COMPLETED
var FAILED
var RUNNING
var WAITING