Skip to content

Commit 01c4794

Browse files
d-w-moorekorydraughn
authored andcommitted
[#823] allow querying for RULE_EXEC_CONTEXT column
1 parent d3cbda0 commit 01c4794

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

irods/models.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ class RuleExec(Model):
3333
last_exe_time = Column(DateTime, "RULE_EXEC_LAST_EXE_TIME", 1010)
3434
frequency = Column(String, "RULE_EXEC_FREQUENCY", 1006)
3535
priority = Column(String, "RULE_EXEC_PRIORITY", 1007)
36-
37-
38-
# # If needed in 4.2.9, we can update the Query class to dynamically
39-
# # attach this field based on server version:
40-
# context = Column(String, 'RULE_EXEC_CONTEXT', 1012)
36+
context = Column(String, 'RULE_EXEC_CONTEXT', 1012, min_version=(4, 3, 0))
4137

4238
# # These are either unused or usually absent:
4339
# exec_status = Column(String,'RULE_EXEC_STATUS', 1011)

irods/test/rule_test.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#! /usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
import io
5+
import json
46
import os
7+
import random
58
import sys
6-
import time
79
import textwrap
10+
import time
811
import unittest
9-
from irods.models import DataObject
12+
from io import open as io_open
13+
14+
from irods.column import Like
1015
from irods.exception import (
1116
FAIL_ACTION_ENCOUNTERED_ERR,
1217
RULE_ENGINE_ERROR,
1318
UnknowniRODSError,
1419
)
15-
import irods.test.helpers as helpers
20+
from irods.models import DataObject, RuleExec
1621
from irods.rule import Rule
17-
from io import open as io_open
18-
import io
19-
22+
from irods.test import helpers
2023

2124
RE_Plugins_installed_run_condition_args = (
2225
os.environ.get("PYTHON_RULE_ENGINE_INSTALLED", "*").lower()[:1] == "y",
@@ -436,6 +439,35 @@ def test_rulefile_in_file_like_object_2__336(self):
436439
self.assertRegex(lines[0], r"\[INTEGER\]\[5\]")
437440
self.assertRegex(lines[1], r"\[STRING\]\[A String\]")
438441

442+
def test_rule_exec_context_column_is_available_via_genquery1__issue_823(self):
443+
rule_id = -1
444+
445+
try:
446+
# Schedule a delayed rule. The amount of delay does not matter as only its existence
447+
# in the catalog matters and we'll be cancelling it immediately after the test.
448+
delay_seconds = 15 * 60
449+
450+
# Generate a unique number for use in querying the rule.
451+
random_int = random.randint(1 << 30, (1 << 31) - 1) # noqa: S311
452+
r = Rule(
453+
self.sess,
454+
body=f'''delay("<PLUSET>{delay_seconds}</PLUSET>") {{ writeLine("serverLog","{random_int}") }}''',
455+
)
456+
# Schedule the delayed rule.
457+
r.execute()
458+
459+
# Get the delayed rule's ID, needed for cancellation.
460+
results = list(self.sess.query(RuleExec).filter(Like(RuleExec.name, f'%"{random_int}"%')))
461+
rule_id = results[0][RuleExec.id]
462+
463+
# Assert context exists, and is JSON-parsable with a non-null-length result.
464+
rule_context = results[0][RuleExec.context]
465+
self.assertGreater(len(json.loads(rule_context)), 0)
466+
finally:
467+
# Remove the delayed rule from the queue.
468+
if rule_id >= 0:
469+
r.remove_by_id(rule_id)
470+
439471

440472
if __name__ == "__main__":
441473
# let the tests find the parent irods lib

0 commit comments

Comments
 (0)