@@ -581,56 +581,56 @@ def create(cls, user, parameters, force=False):
581
581
"""
582
582
TTRN = qdb .sql_connection .TRN
583
583
with TTRN :
584
- command = parameters .command
584
+ if not force :
585
+ command = parameters .command
585
586
586
- # check if a job with the same parameters already exists
587
- sql = """SELECT processing_job_id, email, processing_job_status,
588
- COUNT(aopj.artifact_id)
589
- FROM qiita.processing_job
590
- LEFT JOIN qiita.processing_job_status
591
- USING (processing_job_status_id)
592
- LEFT JOIN qiita.artifact_output_processing_job aopj
593
- USING (processing_job_id)
594
- WHERE command_id = %s AND processing_job_status IN (
595
- 'success', 'waiting', 'running', 'in_construction') {0}
596
- GROUP BY processing_job_id, email,
597
- processing_job_status"""
598
-
599
- # we need to use ILIKE because of booleans as they can be
600
- # false or False
601
- params = []
602
- for k , v in parameters .values .items ():
603
- # this is necessary in case we have an Iterable as a value
604
- # but that is string
605
- if isinstance (v , Iterable ) and not isinstance (v , str ):
606
- for vv in v :
607
- params .extend ([k , str (vv )])
587
+ # check if a job with the same parameters already exists
588
+ sql = """SELECT processing_job_id, processing_job_status
589
+ FROM qiita.processing_job
590
+ LEFT JOIN qiita.processing_job_status
591
+ USING (processing_job_status_id)
592
+ LEFT JOIN qiita.artifact_output_processing_job aopj
593
+ USING (processing_job_id)
594
+ WHERE command_id = %s AND processing_job_status IN (
595
+ 'success', 'waiting', 'running', 'in_construction')
596
+ {0}"""
597
+
598
+ # we need to use ILIKE because of booleans as they can be
599
+ # false or False
600
+ params = []
601
+ for k , v in parameters .values .items ():
602
+ # this is necessary in case we have an Iterable as a value
603
+ # but that is string
604
+ if isinstance (v , Iterable ) and not isinstance (v , str ):
605
+ for vv in v :
606
+ params .extend ([k , str (vv )])
607
+ else :
608
+ params .extend ([k , str (v )])
609
+
610
+ if params :
611
+ # divided by 2 as we have key-value pairs
612
+ len_params = int (len (params )/ 2 )
613
+ sql = sql .format (' AND ' + ' AND ' .join (
614
+ ["command_parameters->>%s = %s" ] * len_params ))
615
+ params = [command .id ] + params
616
+ TTRN .add (sql , params )
608
617
else :
609
- params .extend ([k , str (v )])
610
-
611
- if params :
612
- # divided by 2 as we have key-value pairs
613
- len_params = int (len (params )/ 2 )
614
- sql = sql .format (' AND ' + ' AND ' .join (
615
- ["command_parameters->>%s ILIKE %s" ] * len_params ))
616
- params = [command .id ] + params
617
- TTRN .add (sql , params )
618
- else :
619
- # the sql variable expects the list of parameters but if there
620
- # is no param we need to replace the {0} with an empty string
621
- TTRN .add (sql .format ("" ), [command .id ])
622
-
623
- # checking that if the job status is success, it has children
624
- # [2] status, [3] children count
625
- existing_jobs = [r for r in TTRN .execute_fetchindex ()
626
- if r [2 ] != 'success' or r [3 ] > 0 ]
627
- if existing_jobs and not force :
628
- raise ValueError (
629
- 'Cannot create job because the parameters are the same as '
630
- 'jobs that are queued, running or already have '
631
- 'succeeded:\n %s' % '\n ' .join (
632
- ["%s: %s" % (jid , status )
633
- for jid , _ , status , _ in existing_jobs ]))
618
+ # the sql variable expects the list of parameters but if
619
+ # there is no param we need to replace the {0} with an
620
+ # empty string
621
+ TTRN .add (sql .format ("" ), [command .id ])
622
+
623
+ # checking that if the job status is success, it has children
624
+ # [2] status, [3] children count
625
+ existing_jobs = [r for r in TTRN .execute_fetchindex ()
626
+ if r [2 ] != 'success' or r [3 ] > 0 ]
627
+ if existing_jobs :
628
+ raise ValueError (
629
+ 'Cannot create job because the parameters are the '
630
+ 'same as jobs that are queued, running or already '
631
+ 'have succeeded:\n %s' % '\n ' .join (
632
+ ["%s: %s" % (jid , status )
633
+ for jid , _ , status , _ in existing_jobs ]))
634
634
635
635
sql = """INSERT INTO qiita.processing_job
636
636
(email, command_id, command_parameters,
0 commit comments