Skip to content

Commit 7c848bc

Browse files
committed
Update util.py
1 parent 07fa018 commit 7c848bc

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

Diff for: qiita_db/util.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -2694,7 +2694,7 @@ def MaxRSS_helper(x):
26942694
return y
26952695

26962696

2697-
def update_resource_allocation_table(test=None):
2697+
def update_resource_allocation_table(weeks=1, test=None):
26982698
# Thu, Apr 27, 2023 old allocations (from barnacle) were changed to a
26992699
# better allocation so we default start time 2023-04-28 to
27002700
# use the latests for the newest version
@@ -2705,34 +2705,43 @@ def update_resource_allocation_table(test=None):
27052705
27062706
Parameters:
27072707
----------
2708+
weeks: integer, optional
2709+
Number of weeks for which we want to make a request from slurm.
27082710
test: pandas.DataFrame, optional
27092711
Represents dataframe containing slurm data from 2023-04-28. Used
27102712
for testing only.
27112713
"""
27122714

27132715
# retrieve the most recent timestamp
27142716
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+
"""
27212730

27222731
dates = ['', '']
27232732

27242733
with qdb.sql_connection.TRN:
27252734
sql = sql_timestamp
27262735
qdb.sql_connection.TRN.add(sql)
27272736
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:
27312741
dates[0] = datetime.strptime('2023-04-28', '%Y-%m-%d')
27322742
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)
27362745
dates[1] = date1.strftime('%Y-%m-%d')
27372746

27382747
sql_command = """
@@ -2753,13 +2762,15 @@ def update_resource_allocation_table(test=None):
27532762
pjs.processing_job_status = 'success'
27542763
AND
27552764
pj.external_job_id ~ '^[0-9]+$'
2765+
AND
2766+
CAST(pj.external_job_id AS INTEGER) > %s
27562767
AND
27572768
sra.processing_job_id IS NULL;
27582769
"""
27592770
df = pd.DataFrame()
27602771
with qdb.sql_connection.TRN:
27612772
sql = sql_command
2762-
qdb.sql_connection.TRN.add(sql)
2773+
qdb.sql_connection.TRN.add(sql, sql_args=[slurm_external_id])
27632774
res = qdb.sql_connection.TRN.execute_fetchindex()
27642775
columns = ["processing_job_id", 'external_id']
27652776
df = pd.DataFrame(res, columns=columns)

0 commit comments

Comments
 (0)