brynq-sdk-task-scheduler 1.2.0__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/PKG-INFO +1 -1
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk/task_scheduler/task_scheduler.py +34 -31
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/PKG-INFO +1 -1
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/setup.py +1 -1
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk/task_scheduler/__init__.py +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/not-zip-safe +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/requires.txt +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/brynq_sdk_task_scheduler.egg-info/top_level.txt +0 -0
- {brynq_sdk_task_scheduler-1.2.0 → brynq_sdk_task_scheduler-1.2.1}/setup.cfg +0 -0
|
@@ -29,40 +29,43 @@ class TaskScheduler(BrynQ):
|
|
|
29
29
|
with level DEBUG not is stored
|
|
30
30
|
"""
|
|
31
31
|
super().__init__()
|
|
32
|
-
self.es = Elastic()
|
|
33
32
|
self.mysql = MySQL()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
try:
|
|
34
|
+
self.es = Elastic()
|
|
35
|
+
self.email_after_errors = email_after_errors
|
|
36
|
+
self.customer_db = self.mysql.database
|
|
37
|
+
self.customer_id = self.mysql.raw_query(f'SELECT id FROM sc.customers WHERE dbname = \'{self.customer_db}\'')[0][0]
|
|
38
|
+
self.partner_id = os.getenv('PARTNER_ID').lower().replace(' ', '_') if os.getenv('PARTNER_ID') else 'brynq'
|
|
39
|
+
self.task_id = task_id
|
|
40
|
+
self.loglevel = loglevel
|
|
41
|
+
self.started_at = datetime.datetime.now()
|
|
42
|
+
# If the task is started via the task_scheduler, the following 3 parameters will be passed by the scheduler
|
|
43
|
+
if len(sys.argv[1:4]) > 0:
|
|
44
|
+
self.started_local = False
|
|
45
|
+
self.customer_db, self.task_id, self.run_id = sys.argv[1:4]
|
|
46
|
+
# If the task is started locally, the parameters should be set locally
|
|
47
|
+
else:
|
|
48
|
+
self.started_local = True
|
|
49
|
+
self.run_id = int(round(time.time() * 100000))
|
|
50
|
+
print(self.task_id, self.run_id)
|
|
51
|
+
self.error_count = 0
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
# Check if the log tables exists in the customer database. If not, create them
|
|
54
|
+
# Mysql throws a warning when a table already exists. We don't care so we ignore warnings. (not exceptions!)
|
|
55
|
+
warnings.filterwarnings('ignore')
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
# Check if the task is started on schedule or manual. store in a variable to use later in the script
|
|
58
|
+
self.task_manual_started = self.check_if_task_manual_started()
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
# Creates Elasticsearch index and data view if not exists
|
|
61
|
+
self.es_index = f"task_execution_log_{self.customer_db}_{self.started_at.strftime('%Y_%m')}"
|
|
62
|
+
self.es.create_index(index_name=self.es_index)
|
|
63
|
+
self.es.create_data_view(space_name='interfaces', view_name=f'task_execution_log_{self.customer_db}', name=f'Task execution log {self.customer_db}', time_field='started_at')
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
# Start the task and setup the data in the database
|
|
66
|
+
self.start_task()
|
|
67
|
+
except Exception as e:
|
|
68
|
+
self.error_handling(e)
|
|
66
69
|
|
|
67
70
|
def __count_keys(self, json_obj):
|
|
68
71
|
if not isinstance(json_obj, dict):
|
|
@@ -242,7 +245,7 @@ class TaskScheduler(BrynQ):
|
|
|
242
245
|
'started_at': datetime.datetime.now().isoformat(),
|
|
243
246
|
'partner_id': self.partner_id,
|
|
244
247
|
'customer_id': self.customer_id,
|
|
245
|
-
'customer': os.getenv('
|
|
248
|
+
'customer': os.getenv('BRYNQ_SUBDOMAIN').lower().replace(' ', '_'),
|
|
246
249
|
'file_name': file_name,
|
|
247
250
|
'function_name': function_name,
|
|
248
251
|
'line_number': line_number,
|
|
@@ -315,7 +318,7 @@ class TaskScheduler(BrynQ):
|
|
|
315
318
|
'started_at': datetime.datetime.now().isoformat(),
|
|
316
319
|
'partner_id': self.partner_id,
|
|
317
320
|
'customer_id': self.customer_id,
|
|
318
|
-
'customer': os.getenv('
|
|
321
|
+
'customer': os.getenv('BRYNQ_SUBDOMAIN').lower().replace(' ', '_'),
|
|
319
322
|
'file_name': file_name,
|
|
320
323
|
'function_name': function_name,
|
|
321
324
|
'line_number': line_number,
|
|
@@ -3,7 +3,7 @@ from setuptools import setup
|
|
|
3
3
|
|
|
4
4
|
setup(
|
|
5
5
|
name='brynq_sdk_task_scheduler',
|
|
6
|
-
version='1.2.
|
|
6
|
+
version='1.2.1',
|
|
7
7
|
description='Code to execute tasks in BrynQ.com with the task scheduler',
|
|
8
8
|
long_description='Code to execute tasks in the BrynQ.com platform with the task scheduler',
|
|
9
9
|
author='BrynQ',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|