Fix first_execution_time when used together with pattern
When specifying pattern only in the API request, the returned first_execution_time should be the calculated according to the pattern. When specifying first_execution_time and pattern both in the API request, the first_execution_time will be tweaked according to the pattern. Change-Id: I0c71c2d76584c9b8335d6b379361779191e8c8d2 Story: 2003483 Task: 24750
This commit is contained in:
parent
1448ac031a
commit
a41c86a515
@ -15,6 +15,8 @@
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from dateutil import parser
|
||||
|
||||
from qinling import context as auth_context
|
||||
from qinling.db import api as db_api
|
||||
from qinling import status
|
||||
@ -99,6 +101,31 @@ class TestJobController(base.APITest):
|
||||
|
||||
self.assertEqual(201, resp.status_int)
|
||||
|
||||
res = resp.json
|
||||
self.assertEqual(
|
||||
res["first_execution_time"],
|
||||
res["next_execution_time"]
|
||||
)
|
||||
|
||||
def test_post_both_pattern_and_first_execution_time(self):
|
||||
body = {
|
||||
'name': self.rand_name('job', prefix=self.prefix),
|
||||
'function_id': self.function_id,
|
||||
'pattern': '0 21 * * *',
|
||||
'first_execution_time': str(
|
||||
datetime.utcnow() + timedelta(hours=1)),
|
||||
'count': 10
|
||||
}
|
||||
resp = self.app.post_json('/v1/jobs', body)
|
||||
|
||||
self.assertEqual(201, resp.status_int)
|
||||
|
||||
res = resp.json
|
||||
self.assertGreaterEqual(
|
||||
parser.parse(res["next_execution_time"], ignoretz=True),
|
||||
parser.parse(res["first_execution_time"], ignoretz=True)
|
||||
)
|
||||
|
||||
def test_delete(self):
|
||||
job_id = self.create_job(
|
||||
self.function_id,
|
||||
|
@ -56,26 +56,29 @@ def validate_job(params):
|
||||
|
||||
if not (first_time or pattern):
|
||||
raise exc.InputException(
|
||||
'Pattern or first_execution_time must be specified.'
|
||||
'pattern or first_execution_time must be specified.'
|
||||
)
|
||||
|
||||
if first_time:
|
||||
first_time = validate_next_time(first_time)
|
||||
if not pattern and count and count > 1:
|
||||
raise exc.InputException(
|
||||
'Pattern must be provided if count is greater than 1.'
|
||||
'pattern must be provided if count is greater than 1.'
|
||||
)
|
||||
|
||||
next_time = first_time
|
||||
if not (pattern or count):
|
||||
count = 1
|
||||
|
||||
if pattern:
|
||||
validate_pattern(pattern)
|
||||
if not first_time:
|
||||
next_time = croniter.croniter(pattern, start_time).get_next(
|
||||
datetime.datetime
|
||||
)
|
||||
|
||||
if first_time:
|
||||
start_time = first_time - datetime.timedelta(minutes=1)
|
||||
|
||||
next_time = croniter.croniter(pattern, start_time).get_next(
|
||||
datetime.datetime
|
||||
)
|
||||
first_time = next_time
|
||||
|
||||
return first_time, next_time, count
|
||||
|
||||
|
@ -10,5 +10,5 @@ testscenarios>=0.4 # Apache-2.0/BSD
|
||||
testtools>=2.2.0 # MIT
|
||||
tempest>=17.1.0 # Apache-2.0
|
||||
futurist>=1.2.0 # Apache-2.0
|
||||
|
||||
kubernetes>=6.0.0 # Apache-2.0
|
||||
python-dateutil>=2.5.3 # BSD
|
||||
|
Loading…
x
Reference in New Issue
Block a user