1

嘿,我有以下功能来启动批处理作业。

我的批处理作业有两个参数要传入 --source --destination

def kickoff_transfer_batch(self,item):
    try:
        batch = boto3.client('batch')
        bucket, key = get_s3_bucket_and_key(item.source)
        jobName = 'transfer-'+ key
        jobQueue = 'aws-strikeforce-on-demand-restore-prod'
        jobDefinition = 'aws-strikeforce-transfer-prod'
        source = '--source ' + item.source
        destination ='--destination ' + item.destination

        command = []
        command.append(source)
        command.append(destination)

        submit_job_response = batch.submit_job(
            jobName=jobName,
            jobQueue=jobQueue,
            jobDefinition=jobDefinition,
            containerOverrides={'command': command}
        )
        job_id = submit_job_response['jobId']
        print('Submitted job {} {} to the job queue {}'.format(jobName, job_id, jobQueue))
    except Exception as err:
        item.errored = True
        print("failed: " + item.source)
        print("error: " + str(err))
        stack_trace = traceback.format_exc()
        self._log_error_notes(item.source, err, stack_trace)

我的工作是从批处理中启动的,但是由于我传入--source 和--dest 的方式,我的容器无法启动。这是错误日志

main.py: error: unrecognized arguments: --source file_test.txt --destination file_test.txt

如何修复我的命令列表以传递正确的参数。当我在命令行启动作业时,我只需输入 --source file, --dest file

4

1 回答 1

5

这个答案供以后参考

    def kickoff_transfer_batch(self,item):
    try:
        batch = boto3.client('batch')
        bucket, key = get_s3_bucket_and_key(item.source)
        jobName = 'transfer-'+ key
        jobQueue = 'aws-strikeforce-on-demand-restore-prod'
        jobDefinition = 'aws-strikeforce-transfer-prod'
        command = '--source '+ item.source + '--destination ' + item.destination
        command = command.split()

        submit_job_response = batch.submit_job(
            jobName=jobName,
            jobQueue=jobQueue,
            jobDefinition=jobDefinition,
            containerOverrides={'command': command}
        )
        job_id = submit_job_response['jobId']
        print('Submitted job {} {} to the job queue {}'.format(jobName, job_id, jobQueue))
    except Exception as err:
        item.errored = True
        print("failed: " + item.source)
        print("error: " + str(err))
        stack_trace = traceback.format_exc()
        self._log_error_notes(item.source, err, stack_trace)
于 2018-08-01T18:00:42.303 回答