from flask import make_response, request, abort
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, identifier):
        # extract request data
        data = request.get_json(force=True)

        if 'remove' not in data or data['remove'] is not True:
            abort(400)

        # remove job
        self.jobs.remove(identifier)

        # return success response
        return make_response()
