Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9697336
D613.id1877.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D613.id1877.diff
View Options
diff --git a/swh/scheduler/tests/test_utils.py b/swh/scheduler/tests/test_utils.py
--- a/swh/scheduler/tests/test_utils.py
+++ b/swh/scheduler/tests/test_utils.py
@@ -26,7 +26,6 @@
'args': [],
'kwargs': {},
},
- 'priority': None,
}
self.assertEqual(actual_task, expected_task)
@@ -54,3 +53,27 @@
self.assertEqual(actual_task, expected_task)
mock_datetime.now.assert_called_once_with(tz=timezone.utc)
+
+ @patch('swh.scheduler.utils.datetime')
+ def test_create_task_dict(self, mock_datetime):
+ mock_datetime.now.return_value = 'date'
+
+ actual_task = utils.create_task_dict(
+ 'task-type', 'recurring', 'arg0', 'arg1',
+ priority='low', other_stuff='normal', retries_left=3
+ )
+
+ expected_task = {
+ 'policy': 'recurring',
+ 'type': 'task-type',
+ 'next_run': 'date',
+ 'arguments': {
+ 'args': ('arg0', 'arg1'),
+ 'kwargs': {'other_stuff': 'normal'},
+ },
+ 'priority': 'low',
+ 'retries_left': 3,
+ }
+
+ self.assertEqual(actual_task, expected_task)
+ mock_datetime.now.assert_called_once_with(tz=timezone.utc)
diff --git a/swh/scheduler/utils.py b/swh/scheduler/utils.py
--- a/swh/scheduler/utils.py
+++ b/swh/scheduler/utils.py
@@ -40,10 +40,13 @@
(swh.scheduler.backend.create_tasks)
"""
- priority = None
- if 'priority' in kwargs:
- priority = kwargs.pop('priority')
- return {
+ task_extra = {}
+ for extra_key in ['priority', 'retries_left']:
+ if extra_key in kwargs:
+ extra_val = kwargs.pop(extra_key)
+ task_extra[extra_key] = extra_val
+
+ task = {
'policy': policy,
'type': type,
'next_run': datetime.now(tz=timezone.utc),
@@ -51,8 +54,9 @@
'args': args if args else [],
'kwargs': kwargs if kwargs else {},
},
- 'priority': priority,
}
+ task.update(task_extra)
+ return task
def create_oneshot_task_dict(type, *args, **kwargs):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 17, 11:28 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3215652
Attached To
D613: swh.scheduler.utils: Allow to add more task information
Event Timeline
Log In to Comment