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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq_sdk_task_scheduler
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Code to execute tasks in BrynQ.com with the task scheduler
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -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
- self.email_after_errors = email_after_errors
35
- self.customer_db = self.mysql.database
36
- self.customer_id = self.mysql.raw_query(f'SELECT id FROM sc.customers WHERE dbname = \'{self.customer_db}\'')[0][0]
37
- self.partner_id = os.getenv('PARTNER_ID').lower().replace(' ', '_') if os.getenv('PARTNER_ID') else 'brynq'
38
- self.task_id = task_id
39
- self.loglevel = loglevel
40
- self.started_at = datetime.datetime.now()
41
- # If the task is started via the task_scheduler, the following 3 parameters will be passed by the scheduler
42
- if len(sys.argv[1:4]) > 0:
43
- self.started_local = False
44
- self.customer_db, self.task_id, self.run_id = sys.argv[1:4]
45
- # If the task is started locally, the parameters should be set locally
46
- else:
47
- self.started_local = True
48
- self.run_id = int(round(time.time() * 100000))
49
- print(self.task_id, self.run_id)
50
- self.error_count = 0
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
- # Check if the log tables exists in the customer database. If not, create them
53
- # Mysql throws a warning when a table already exists. We don't care so we ignore warnings. (not exceptions!)
54
- warnings.filterwarnings('ignore')
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
- # Check if the task is started on schedule or manual. store in a variable to use later in the script
57
- self.task_manual_started = self.check_if_task_manual_started()
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
- # Creates Elasticsearch index and data view if not exists
60
- self.es_index = f"task_execution_log_{self.customer_db}_{self.started_at.strftime('%Y_%m')}"
61
- self.es.create_index(index_name=self.es_index)
62
- 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')
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
- # Start the task and setup the data in the database
65
- self.start_task()
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('BRYNQ_CUSTOMER_NAME').lower().replace(' ', '_'),
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('BRYNQ_CUSTOMER_NAME').lower().replace(' ', '_'),
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,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-task-scheduler
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Code to execute tasks in BrynQ.com with the task scheduler
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name='brynq_sdk_task_scheduler',
6
- version='1.2.0',
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',