<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def submit_jobs(self, link, job_dict=None, job_archive=None, stream=sys.stdout):
 """Run the `Link` with all of the items job_dict as input. If job_dict is None, the job_dict will be take from link.jobs Returns a `JobStatus` enum """

        failed = False
        if job_dict is None:
            job_dict = link.jobs

        for job_key, job_details in sorted(job_dict.items()):
            job_config = job_details.job_config
            # clean failed jobs
            if job_details.status == JobStatus.failed:
                clean_job(job_details.logfile,
                          job_details.outfiles, self._dry_run)
                # clean_job(job_details.logfile, {}, self._dry_run)
            job_config['logfile'] = job_details.logfile
            new_job_details = self.dispatch_job(
                link, job_key, job_archive, stream)
            if new_job_details.status == JobStatus.failed:
                failed = True
                clean_job(new_job_details.logfile,
                          new_job_details.outfiles, self._dry_run)
            link.jobs[job_key] = new_job_details
        if failed:
            return JobStatus.failed
        return JobStatus.done