@@ -2694,7 +2694,7 @@ def MaxRSS_helper(x):
2694
2694
return y
2695
2695
2696
2696
2697
- def update_resource_allocation_table (test = None ):
2697
+ def update_resource_allocation_table (weeks = 1 , test = None ):
2698
2698
# Thu, Apr 27, 2023 old allocations (from barnacle) were changed to a
2699
2699
# better allocation so we default start time 2023-04-28 to
2700
2700
# use the latests for the newest version
@@ -2705,34 +2705,43 @@ def update_resource_allocation_table(test=None):
2705
2705
2706
2706
Parameters:
2707
2707
----------
2708
+ weeks: integer, optional
2709
+ Number of weeks for which we want to make a request from slurm.
2708
2710
test: pandas.DataFrame, optional
2709
2711
Represents dataframe containing slurm data from 2023-04-28. Used
2710
2712
for testing only.
2711
2713
"""
2712
2714
2713
2715
# retrieve the most recent timestamp
2714
2716
sql_timestamp = """
2715
- SELECT
2716
- sra.job_start
2717
- FROM
2718
- qiita.slurm_resource_allocations sra
2719
- ORDER BY job_start DESC;
2720
- """
2717
+ SELECT
2718
+ pj.external_job_id,
2719
+ sra.job_start
2720
+ FROM
2721
+ qiita.processing_job pj
2722
+ JOIN
2723
+ qiita.slurm_resource_allocations sra
2724
+ ON
2725
+ pj.processing_job_id = sra.processing_job_id
2726
+ ORDER BY
2727
+ sra.job_start DESC
2728
+ LIMIT 1;
2729
+ """
2721
2730
2722
2731
dates = ['' , '' ]
2723
2732
2724
2733
with qdb .sql_connection .TRN :
2725
2734
sql = sql_timestamp
2726
2735
qdb .sql_connection .TRN .add (sql )
2727
2736
res = qdb .sql_connection .TRN .execute_fetchindex ()
2728
- columns = ['timestamp' ]
2729
- timestamps = pd .DataFrame (res , columns = columns )
2730
- if len (timestamps ['timestamp' ]) == 0 :
2737
+ slurm_external_id , timestamp = res [0 ]
2738
+ if slurm_external_id is None :
2739
+ slurm_external_id = 0
2740
+ if timestamp is None :
2731
2741
dates [0 ] = datetime .strptime ('2023-04-28' , '%Y-%m-%d' )
2732
2742
else :
2733
- dates [0 ] = str (timestamps ['timestamp' ].iloc [0 ]).split (' ' )[0 ]
2734
- date0 = datetime .strptime (dates [0 ], '%Y-%m-%d' )
2735
- date1 = date0 + timedelta (weeks = 1 )
2743
+ dates [0 ] = timestamp
2744
+ date1 = dates [0 ] + timedelta (weeks )
2736
2745
dates [1 ] = date1 .strftime ('%Y-%m-%d' )
2737
2746
2738
2747
sql_command = """
@@ -2753,13 +2762,15 @@ def update_resource_allocation_table(test=None):
2753
2762
pjs.processing_job_status = 'success'
2754
2763
AND
2755
2764
pj.external_job_id ~ '^[0-9]+$'
2765
+ AND
2766
+ CAST(pj.external_job_id AS INTEGER) > %s
2756
2767
AND
2757
2768
sra.processing_job_id IS NULL;
2758
2769
"""
2759
2770
df = pd .DataFrame ()
2760
2771
with qdb .sql_connection .TRN :
2761
2772
sql = sql_command
2762
- qdb .sql_connection .TRN .add (sql )
2773
+ qdb .sql_connection .TRN .add (sql , sql_args = [ slurm_external_id ] )
2763
2774
res = qdb .sql_connection .TRN .execute_fetchindex ()
2764
2775
columns = ["processing_job_id" , 'external_id' ]
2765
2776
df = pd .DataFrame (res , columns = columns )
0 commit comments