from flask import abort
from flask import make_response
from flask import request
from flask.views import View

from pycs.jobs.JobRunner import JobRunner


class RemoveJob(View):
    """
    remove a job from the job runners list
    """
    # pylint: disable=arguments-differ
    methods = ['POST']

    def __init__(self, jobs: JobRunner):
        # pylint: disable=invalid-name
        self.jobs = jobs

    def dispatch_request(self, job_id):
        # extract request data
        data = request.get_json(force=True)

        if not data.get('remove', False):
            abort(400, "remove flag is missing")

        # remove job
        self.jobs.remove(job_id)

        # return success response
        return make_response()
