# Path: ecs_scheduler/datacontext.py
# class JobAlreadyExists(JobError):
#     """Job exists error."""
#     pass
# 
# class JobNotFound(JobError):
#     """Job not found error."""
#     pass
# 
# class InvalidJobData(JobError):
#     """Invalid job data error."""
# 
#     def __init__(self, job_id, errors, *args, **kwargs):
#         """
#         Create a job error.
# 
#         :param job_id: The job id related to the failed jobs call
#         :param errors: Job validation errors
#         :param *args: Additional exception positional arguments
#         :param **kwargs: Additional exception keyword arugments
#         """
#         super().__init__(job_id, *args, **kwargs)
#         self.errors = errors
# 
# Path: ecs_scheduler/models.py
# class Pagination:
#     """
#     Job pagination parameters.
# 
#     :param skip: The number of jobs to skip
#     :param count: The number of jobs to return
#     :param total: The total number of jobs across all pages;
#                   used to calculate next and prev page links
#     """
#     skip: int
#     count: int
#     total: int = 0
# 
# class JobOperation:
#     """
#     A job operation used to communicate changes to the scheduler via
#     the ops queue between the web api and the scheduler daemon.
# 
#     :attribute ADD: Add operation label
#     :attribute MODIFY: Modify operation label
#     :attribute REMOVE: Remove operation label
#     """
#     ADD = 1
#     MODIFY = 2
#     REMOVE = 3
# 
#     @classmethod
#     def add(cls, job_id):
#         """
#         Create an add job operation.
# 
#         :param job_id: The string id of the job to add to the scheduler
#         """
#         return cls(cls.ADD, job_id)
# 
#     @classmethod
#     def modify(cls, job_id):
#         """
#         Create a modify job operation
# 
#         :param job_id: The string id of the job to modify in the scheduler
#         """
#         return cls(cls.MODIFY, job_id)
# 
#     @classmethod
#     def remove(cls, job_id):
#         """
#         Create a remove job operation.
# 
#         :param job_id: The string id of the job to remove from the scheduler
#         """
#         return cls(cls.REMOVE, job_id)
# 
#     def __init__(self, operation, job_id):
#         """
#         Create a job operation.
# 
#         Use the factory class methods instead of __init___ directly
#         to create an instance.
# 
#         :param operation: The operation label
#         :param job_id: The string id of the job to apply the operation to
#         """
#         self.operation = operation
#         self.job_id = job_id
# 
# Path: ecs_scheduler/serialization.py
# class PaginationSchema(marshmallow.Schema):
#     """Schema for pagination arguments."""
#     skip = marshmallow.fields.Integer(missing=0)
#     count = marshmallow.fields.Integer(missing=10)
# 
#     @marshmallow.post_load
#     def make_pagination(self, data):
#         for field in self.fields.keys():
#             data[field] = max(0, data[field])
#         return Pagination(**data)
# 
#     @marshmallow.pre_dump
#     def adjust_page_frame(self, obj):
#         if (
#             obj.total <= 0
#             or (obj.skip + obj.count) <= 0
#             or obj.skip >= obj.total
#         ):
#             return {}
#         obj.skip = max(0, obj.skip)
# 
#     @marshmallow.post_dump
#     def strip_defaults(self, data):
#         return {
#             k: v for k, v in data.items()
#             if v != self._get_field_missing_value(k)
#         }
# 
#     def _get_field_missing_value(self, name):
#         field = self.fields.get(name)
#         return field.missing if field else None
# 
# class JobResponseSchema(JobSchema):
#     """
#     Schema of a job response.
# 
#     This extends JobSchema to deserialize a Job into a REST JSON
#     representation.
# 
#     Used for serialization only.
#     """
#     # override id to include in dump output
#     id = marshmallow.fields.String(dump_only=True)
#     link = marshmallow.fields.Method('link_generator', dump_only=True)
#     lastRun = marshmallow.fields.LocalDateTime(dump_only=True)
#     lastRunTasks = marshmallow.fields.List(
#         marshmallow.fields.Nested(TaskInfoSchema), dump_only=True
#     )
#     estimatedNextRun = marshmallow.fields.LocalDateTime(dump_only=True)
# 
#     def __init__(self, link_func, *args, **kwargs):
#         self._link_func = link_func
#         super().__init__(*args, **kwargs)
# 
#     def link_generator(self, obj):
#         return self._link_func(obj['id'])


import functools
import logging
import flask
import flask_restful
from itertools import islice
from ..datacontext import JobAlreadyExists, JobNotFound, InvalidJobData
from ..models import Pagination, JobOperation
from ..serialization import PaginationSchema, JobResponseSchema

    def delete(self, job_id):
        """
        Delete job
        Delete and unschedule the specified job.
        ---
        tags:
            - jobs
        produces:
            - application/json
        parameters:
            -   name: job_id
                in: path
                type: string
                required: true
                description: the job id
        responses:
            200:
                description: Job deleted
            404:
                description: Job not found
            default:
                description: Server error
        """
        try:
            self._dc.delete(job_id)
        except JobNotFound:
            self._raise_job_notfound(job_id)
        web_response = {'id': job_id}
        _post_operation(

# Path: ecs_scheduler/datacontext.py
# class JobAlreadyExists(JobError):
#     """Job exists error."""
#     pass
# 
# class JobNotFound(JobError):
#     """Job not found error."""
#     pass
# 
# class InvalidJobData(JobError):
#     """Invalid job data error."""
# 
#     def __init__(self, job_id, errors, *args, **kwargs):
#         """
#         Create a job error.
# 
#         :param job_id: The job id related to the failed jobs call
#         :param errors: Job validation errors
#         :param *args: Additional exception positional arguments
#         :param **kwargs: Additional exception keyword arugments
#         """
#         super().__init__(job_id, *args, **kwargs)
#         self.errors = errors
# 
# Path: ecs_scheduler/models.py
# class Pagination:
#     """
#     Job pagination parameters.
# 
#     :param skip: The number of jobs to skip
#     :param count: The number of jobs to return
#     :param total: The total number of jobs across all pages;
#                   used to calculate next and prev page links
#     """
#     skip: int
#     count: int
#     total: int = 0
# 
# class JobOperation:
#     """
#     A job operation used to communicate changes to the scheduler via
#     the ops queue between the web api and the scheduler daemon.
# 
#     :attribute ADD: Add operation label
#     :attribute MODIFY: Modify operation label
#     :attribute REMOVE: Remove operation label
#     """
#     ADD = 1
#     MODIFY = 2
#     REMOVE = 3
# 
#     @classmethod
#     def add(cls, job_id):
#         """
#         Create an add job operation.
# 
#         :param job_id: The string id of the job to add to the scheduler
#         """
#         return cls(cls.ADD, job_id)
# 
#     @classmethod
#     def modify(cls, job_id):
#         """
#         Create a modify job operation
# 
#         :param job_id: The string id of the job to modify in the scheduler
#         """
#         return cls(cls.MODIFY, job_id)
# 
#     @classmethod
#     def remove(cls, job_id):
#         """
#         Create a remove job operation.
# 
#         :param job_id: The string id of the job to remove from the scheduler
#         """
#         return cls(cls.REMOVE, job_id)
# 
#     def __init__(self, operation, job_id):
#         """
#         Create a job operation.
# 
#         Use the factory class methods instead of __init___ directly
#         to create an instance.
# 
#         :param operation: The operation label
#         :param job_id: The string id of the job to apply the operation to
#         """
#         self.operation = operation
#         self.job_id = job_id
# 
# Path: ecs_scheduler/serialization.py
# class PaginationSchema(marshmallow.Schema):
#     """Schema for pagination arguments."""
#     skip = marshmallow.fields.Integer(missing=0)
#     count = marshmallow.fields.Integer(missing=10)
# 
#     @marshmallow.post_load
#     def make_pagination(self, data):
#         for field in self.fields.keys():
#             data[field] = max(0, data[field])
#         return Pagination(**data)
# 
#     @marshmallow.pre_dump
#     def adjust_page_frame(self, obj):
#         if (
#             obj.total <= 0
#             or (obj.skip + obj.count) <= 0
#             or obj.skip >= obj.total
#         ):
#             return {}
#         obj.skip = max(0, obj.skip)
# 
#     @marshmallow.post_dump
#     def strip_defaults(self, data):
#         return {
#             k: v for k, v in data.items()
#             if v != self._get_field_missing_value(k)
#         }
# 
#     def _get_field_missing_value(self, name):
#         field = self.fields.get(name)
#         return field.missing if field else None
# 
# class JobResponseSchema(JobSchema):
#     """
#     Schema of a job response.
# 
#     This extends JobSchema to deserialize a Job into a REST JSON
#     representation.
# 
#     Used for serialization only.
#     """
#     # override id to include in dump output
#     id = marshmallow.fields.String(dump_only=True)
#     link = marshmallow.fields.Method('link_generator', dump_only=True)
#     lastRun = marshmallow.fields.LocalDateTime(dump_only=True)
#     lastRunTasks = marshmallow.fields.List(
#         marshmallow.fields.Nested(TaskInfoSchema), dump_only=True
#     )
#     estimatedNextRun = marshmallow.fields.LocalDateTime(dump_only=True)
# 
#     def __init__(self, link_func, *args, **kwargs):
#         self._link_func = link_func
#         super().__init__(*args, **kwargs)
# 
#     def link_generator(self, obj):
#         return self._link_func(obj['id'])


# Path: ecs_scheduler/webapi/jobs.py
import functools
import logging
import flask
import flask_restful
from itertools import islice
from ..datacontext import JobAlreadyExists, JobNotFound, InvalidJobData
from ..models import Pagination, JobOperation
from ..serialization import PaginationSchema, JobResponseSchema


    def delete(self, job_id):
        """
        Delete job
        Delete and unschedule the specified job.
        ---
        tags:
            - jobs
        produces:
            - application/json
        parameters:
            -   name: job_id
                in: path
                type: string
                required: true
                description: the job id
        responses:
            200:
                description: Job deleted
            404:
                description: Job not found
            default:
                description: Server error
        """
        try:
            self._dc.delete(job_id)
        except JobNotFound:
            self._raise_job_notfound(job_id)
        web_response = {'id': job_id}
        _post_operation(

            JobOperation.remove(job_id), self._ops_queue, web_response