brynq-sdk-task-scheduler 2.0.0__tar.gz → 2.0.2__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: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Code to execute tasks in BrynQ.com with the task scheduler
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: brynq-sdk-task-scheduler
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Code to execute tasks in BrynQ.com with the task scheduler
5
5
  Home-page: UNKNOWN
6
6
  Author: BrynQ
@@ -1,6 +1,4 @@
1
1
  setup.py
2
- brynq_sdk/task_scheduler/__init__.py
3
- brynq_sdk/task_scheduler/task_scheduler.py
4
2
  brynq_sdk_task_scheduler.egg-info/PKG-INFO
5
3
  brynq_sdk_task_scheduler.egg-info/SOURCES.txt
6
4
  brynq_sdk_task_scheduler.egg-info/dependency_links.txt
@@ -0,0 +1,5 @@
1
+ brynq-sdk-brynq<2,>=1
2
+ brynq-sdk-functions<2,>=1
3
+ brynq-sdk-mysql<1.0.1,>=1
4
+ brynq-sdk-mandrill<1.1.2,>=1
5
+ brynq-sdk-elastic<3,>=2
@@ -1,21 +1,20 @@
1
- from setuptools import setup
2
-
1
+ from setuptools import setup, find_namespace_packages
3
2
 
4
3
  setup(
5
4
  name='brynq_sdk_task_scheduler',
6
- version='2.0.0',
5
+ version='2.0.2',
7
6
  description='Code to execute tasks in BrynQ.com with the task scheduler',
8
7
  long_description='Code to execute tasks in the BrynQ.com platform with the task scheduler',
9
8
  author='BrynQ',
10
9
  author_email='support@brynq.com',
11
- packages=["brynq_sdk.task_scheduler"],
10
+ packages=find_namespace_packages(include=['brynq_sdk*']),
12
11
  license='BrynQ License',
13
12
  install_requires=[
14
- 'brynq-sdk-brynq>=1',
15
- 'brynq-sdk-functions>=1',
16
- 'brynq-sdk-mysql>=1',
17
- 'brynq-sdk-mandrill>=1',
18
- 'brynq-sdk-elastic>=2'
13
+ 'brynq-sdk-brynq>=1,<2',
14
+ 'brynq-sdk-functions>=1,<2',
15
+ 'brynq-sdk-mysql>=1,<1.0.1',
16
+ 'brynq-sdk-mandrill>=1,<1.1.2',
17
+ 'brynq-sdk-elastic>=2,<3'
19
18
  ],
20
19
  zip_safe=False,
21
20
  )
@@ -1 +0,0 @@
1
- from brynq_sdk.task_scheduler.task_scheduler import TaskScheduler
@@ -1,441 +0,0 @@
1
- import sys
2
- import os
3
- import datetime
4
- import inspect
5
- import time
6
- import typing
7
- import traceback
8
- import pandas as pd
9
- import json
10
- import requests
11
- from brynq_sdk.mandrill import MailClient
12
- from brynq_sdk.functions import Functions
13
- from brynq_sdk.brynq import BrynQ
14
- from brynq_sdk.mysql import MySQL
15
- from brynq_sdk.elastic import Elastic
16
- import warnings
17
- import re
18
-
19
-
20
- class TaskScheduler(BrynQ):
21
-
22
- def __init__(self, task_id: int = None, loglevel: str = 'INFO', email_after_errors: bool = False):
23
- """
24
- The TaskScheduler is responsible for the logging to the database. Based on this logging, the next reload will
25
- start or not and warning will be given or not
26
- :param task_id: The ID from the task as saved in the task_scheduler table in the customer database
27
- :param email_after_errors: a True or False value. When True, there will be send an email to a contactperson of the customer (as given in the database) with the number of errors
28
- :param loglevel: Chose on which level you want to store the logs. Default is INFO. that means that a logline
29
- with level DEBUG not is stored
30
- """
31
- super().__init__()
32
- self.mysql = MySQL()
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.customer = os.getenv('BRYNQ_SUBDOMAIN').lower().replace(' ', '_')
39
- self.partner_id = os.getenv('PARTNER_ID').lower().replace(' ', '_') if os.getenv('PARTNER_ID') else 'brynq'
40
- self.write_logs_to_mysql = os.getenv('WRITE_LOGS_TO_MSYQL') if os.getenv('WRITE_LOGS_TO_MSYQL') else False
41
- self.task_id = task_id
42
- self.loglevel = loglevel
43
- self.started_at = datetime.datetime.now()
44
- # If the task is started via the task_scheduler, the following 3 parameters will be passed by the scheduler
45
- if len(sys.argv[1:4]) > 0:
46
- self.started_local = False
47
- self.customer_db, self.task_id, self.run_id = sys.argv[1:4]
48
- # If the task is started locally, the parameters should be set locally
49
- else:
50
- self.started_local = True
51
- self.run_id = int(round(time.time() * 100000))
52
- print(self.task_id, self.run_id)
53
- self.error_count = 0
54
-
55
- # Check if the log tables exists in the customer database. If not, create them
56
- # Mysql throws a warning when a table already exists. We don't care so we ignore warnings. (not exceptions!)
57
- warnings.filterwarnings('ignore')
58
-
59
- # Check if the task is started on schedule or manual. store in a variable to use later in the script
60
- self.task_manual_started = self.check_if_task_manual_started()
61
-
62
- # Creates Elasticsearch index and data view if not exists
63
- self.es_index = f"task_execution_log_{self.customer_db}"
64
- self.es.create_index(index_name=self.es_index)
65
- 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')
66
-
67
- # Start the task and setup the data in the database
68
- self.start_task()
69
- except Exception as e:
70
- self.error_handling(e)
71
-
72
- def __count_keys(self, json_obj):
73
- if not isinstance(json_obj, dict):
74
- return 0
75
- key_count = 0
76
- for key, value in json_obj.items():
77
- if not isinstance(value, dict):
78
- key_count += 1 # Count the current key
79
- else:
80
- key_count += self.__count_keys(value) # Recursively count keys in nested dictionaries
81
- return key_count
82
-
83
- def __get_caller_info(self):
84
- stack = inspect.stack()
85
- caller_frame = stack[2][0]
86
- file_name = caller_frame.f_code.co_filename
87
- line_number = caller_frame.f_lineno
88
- function_name = stack[2][3]
89
- return file_name, line_number, function_name
90
-
91
- def create_task_execution_steps(self, step_details: list):
92
- """
93
- Check if the given steps already exists in the task_execution_steps table. If not, update or insert the values in the table
94
- :param step_details: list of dicts. Each dict must contain task details according to required_fields.
95
- Example: step_details = [
96
- {'nr': 1, 'description': 'test'},
97
- {'nr': 2, 'description': 'test2'}
98
- ]
99
- :return: error (str) or response of mysql
100
- """
101
- # Check if the required fields are available in the given list
102
- required_fields = ['nr', 'description']
103
- for step in step_details:
104
- for field in required_fields:
105
- if field not in step.keys():
106
- return 'Field {field} is required in step {step}. Required fields are: {required_fields}'.format(
107
- field=field, step=step, required_fields=tuple(required_fields))
108
-
109
- # Reformat the list of dictionaries to a valid MySQL query
110
- values = ','.join(str((self.task_id, step['nr'], step['description'])) for step in step_details)
111
- response = self.mysql.raw_query("INSERT INTO task_execution_steps (`task_id`, `nr`, `description`) "
112
- "VALUES {step_values} ON DUPLICATE KEY UPDATE `description` = VALUES(description)".format(
113
- step_values=values), insert=True)
114
- return response
115
-
116
- def check_if_task_manual_started(self):
117
- """
118
- Check if the task manual is started of on schedule. If it's manual started, that's important for the variables in the db_variables function.
119
- In that case the dynamic variables should be used instead of the static ones
120
- :return: True of False
121
- """
122
- response = self.mysql.select('task_scheduler', 'run_instant', f'WHERE id = {self.task_id}')[0][0]
123
- if response == 1:
124
- # Reset the 1 back to 0 before sending the result
125
- self.mysql.update('task_scheduler', ['run_instant'], [0], 'WHERE `id` = {}'.format(self.task_id))
126
- return True
127
- else:
128
- return False
129
-
130
- def start_task(self):
131
- """
132
- Start the task and write this to the database. While the status is running, the task will not start again
133
- :return: if the update to the database is successful or not
134
- """
135
- # If the task is started from a local instance (not the task_scheduler), create a start log row in the task_scheduler_log
136
- if self.started_local:
137
- self.mysql.raw_query(f"INSERT INTO `task_scheduler_log` (reload_id, task_id, reload_status, started_at, finished_at) VALUES ({self.run_id}, {self.task_id}, 'Running', '{self.started_at}', null)", insert=True)
138
- return self.mysql.update('task_scheduler', ['status', 'step_nr'], ['RUNNING', 1], 'WHERE `id` = {}'.format(self.task_id))
139
-
140
- def db_variable(self, variable_name: str, default_value_if_temp_is_empty: bool = False):
141
- """
142
- Get a value from the task_variables table corresponding with the given name. If the task is manually started
143
- (run_instant = 1), then the temp_value will be returned. This is to give the possibility for users in the frontend to run
144
- a task once manual with other values then normal without overwriting the normal values.
145
- :param variable_name: the name of the variable
146
- :param default_value_if_temp_is_empty: bool to determine whether default value should be used if temp value is empty when manually started
147
- :return: the value of the given variable.
148
- """
149
- if self.task_manual_started is True:
150
- response = self.mysql.select('task_variables', 'temp_value, value',
151
- f'WHERE name = \'{variable_name}\' AND task_id = {self.task_id}')
152
- else:
153
- response = self.mysql.select('task_variables', 'value',
154
- f'WHERE name = \'{variable_name}\' AND task_id = {self.task_id}')
155
- if len(response) == 0:
156
- raise Exception(f'Variable with name \'{variable_name}\' does not exist')
157
- else:
158
- value = response[0][0]
159
- if value is None and default_value_if_temp_is_empty is True and len(response[0]) > 0:
160
- value = response[0][1]
161
- return value
162
-
163
- def write_execution_log(self, message: str, data, loglevel: str = 'INFO', full_extract: bool = False):
164
- """
165
- Writes messages to the database. Give the message and the level of the log
166
- :param message: A string with a message for the log
167
- :param loglevel: You can choose between DEBUG, INFO, ERROR or CRITICAL (DEBUG is most granulated, CRITICAL the less)
168
- :param data: Uploaded data by the interface that has to be logged in ElasticSearch, if you have nothing to log, use None
169
- :param full_extract: If the data is a full load, set this to True. This will prevent the payload from being logged in ElasticSearch
170
- :return: If writing to the database is successful or not
171
- """
172
-
173
- # Validate if the provided loglevel is valid
174
- allowed_loglevels = ['DEBUG', 'INFO', 'ERROR', 'CRITICAL']
175
- if loglevel not in allowed_loglevels:
176
- raise Exception('You\'ve entered a not allowed loglevel. Choose one of: {}'.format(allowed_loglevels))
177
-
178
- # Count the errors for relevant log levels
179
- if loglevel == 'ERROR' or loglevel == 'CRITICAL':
180
- self.error_count += 1
181
-
182
- # For Elastic, we need to have the data in JSON format. Handling different data types and preparing extra payload information based on the data type
183
- # If the data is just a series, count rows, columns and cells
184
- if isinstance(data, pd.Series):
185
- dataframe = pd.DataFrame(data).T
186
- extra_payload = {
187
- 'rows': len(dataframe),
188
- 'columns': len(dataframe.columns),
189
- 'cells': len(dataframe) * len(dataframe.columns),
190
- }
191
- if not full_extract:
192
- extra_payload['payload'] = dataframe.to_json(orient='records')
193
- # If the data is a list, count rows, columns and cells
194
- elif isinstance(data, dict):
195
- records = self.__count_keys(data)
196
- extra_payload = {
197
- 'rows': 1,
198
- 'columns': records,
199
- 'cells': records,
200
- }
201
- if not full_extract:
202
- extra_payload['payload'] = data
203
- elif isinstance(data, pd.DataFrame):
204
- extra_payload = {
205
- 'rows': len(data),
206
- 'columns': len(data.columns),
207
- 'cells': len(data) * len(data.columns),
208
- }
209
- if not full_extract:
210
- extra_payload['payload'] = data.to_json(orient='records')
211
- # If the data is a response from an URL request, also store all the information about the URL request.
212
- elif isinstance(data, requests.Response):
213
- records = 1
214
- if data.request.body is not None:
215
- records = self.__count_keys(json.loads(data.request.body))
216
- if isinstance(data.request.body, bytes):
217
- data.request.body = data.request.body.decode('utf-8')
218
- extra_payload = {
219
- 'response': data.text,
220
- 'status_code': data.status_code,
221
- 'url': data.url,
222
- 'method': data.request.method,
223
- 'rows': 1,
224
- 'columns': records,
225
- 'cells': records,
226
- }
227
- if not full_extract:
228
- extra_payload['payload'] = data.request.body
229
- elif data is None:
230
- extra_payload = {}
231
- else:
232
- extra_payload = {
233
- 'data_type': str(type(data)),
234
- }
235
- if not full_extract:
236
- extra_payload['payload'] = data
237
-
238
- # Modify payload based on 'full_load' flag
239
- if data is not None and full_extract is True:
240
- extra_payload['full_load'] = True
241
- elif data is not None and full_extract is False:
242
- extra_payload['full_load'] = False
243
-
244
- # Get the linenumber from where the logline is executed.
245
- file_name, line_number, function_name = self.__get_caller_info()
246
-
247
- # Put everything together in the payload for ElasticSearch and send it
248
- payload = {
249
- 'task_id': self.task_id,
250
- 'reload_id': self.run_id,
251
- 'started_at': datetime.datetime.now().isoformat(),
252
- 'partner_id': self.partner_id,
253
- 'customer_id': self.customer_id,
254
- 'customer': self.customer,
255
- 'file_name': file_name,
256
- 'function_name': function_name,
257
- 'line_number': line_number,
258
- 'task_loglevel': self.loglevel,
259
- 'line_loglevel': loglevel,
260
- 'message': message
261
- }
262
- payload.update(extra_payload)
263
- self.es.post_document(index_name=self.es_index, document=payload)
264
-
265
- # Write the logline to the MYSQL database, depends on the chosen loglevel in the task
266
- print('{} at line: {}'.format(message, line_number))
267
-
268
- if self.write_logs_to_mysql:
269
- # Remove quotes from message since these break the query
270
- message = re.sub("[']", '', message)
271
- query = "INSERT INTO `task_execution_log` (reload_id, task_id, log_level, created_at, line_number, message) VALUES ({}, {}, '{}', '{}', {}, '{}')".format(self.run_id, self.task_id, loglevel, datetime.datetime.now(), line_number, message)
272
- if self.loglevel == 'DEBUG' or (self.loglevel == 'INFO' and loglevel != 'DEBUG') or (self.loglevel == 'ERROR' and loglevel in ['ERROR', 'CRITICAL']) or (self.loglevel == 'CRITICAL' and loglevel == 'CRITICAL'):
273
- return self.mysql.raw_query(query, insert=True)
274
-
275
- def update_execution_step(self, step_number: int):
276
- """
277
- Update the current step number in the task_scheduler table so that user's in the frontend of BrynQ can see where a task is at any moment
278
- :param step_number: Give only a number
279
- :return: nothing
280
- """
281
- # Update the step number in the task_scheduler table
282
- return self.mysql.update('task_scheduler', ['step_nr'], [step_number], 'WHERE `id` = {}'.format(self.task_id))
283
-
284
- def error_handling(self, e: Exception, breaking=True, send_to_teams=False):
285
- """
286
- This function handles errors that occur in the scheduler. Logs the traceback, updates run statuses and notifies users
287
- :param e: the Exception that is to be handled
288
- :param task_id: The scheduler task id
289
- :param mysql_con: The connection which is used to update the scheduler task status
290
- :param logger: The logger that is used to write the logging status to
291
- :param breaking: Determines if the error is breaking or code will continue
292
- :param started_at: Give the time the task is started
293
- :return: nothing
294
- """
295
- # Get the linenumber from where the logline is executed.
296
- file_name, line_number, function_name = self.__get_caller_info()
297
-
298
- # Preparing the primary payload with error details for upload to elastic and send it
299
- payload = {
300
- 'task_id': self.task_id,
301
- 'reload_id': self.run_id,
302
- 'started_at': datetime.datetime.now().isoformat(),
303
- 'partner_id': self.partner_id,
304
- 'customer_id': self.customer_id,
305
- 'customer': self.customer,
306
- 'file_name': file_name,
307
- 'function_name': function_name,
308
- 'line_number': line_number,
309
- 'task_loglevel': self.loglevel,
310
- 'line_loglevel': 'CRITICAL',
311
- 'message': str(e),
312
- 'traceback': traceback.format_exc()
313
- }
314
- self.es.post_document(index_name=self.es_index, document=payload)
315
-
316
- self.error_count += 1
317
- # Get scheduler task details for logging
318
- task_details = \
319
- self.mysql.select('task_scheduler, data_interfaces', 'data_interfaces.docker_image, data_interfaces.runfile_path', 'WHERE task_scheduler.data_interface_id = data_interfaces.id AND task_scheduler.id = {}'.format(self.task_id))[0]
320
- taskname = task_details[0]
321
- customer = task_details[1].split('/')[-1].split('.')[0]
322
- now = datetime.datetime.now()
323
-
324
- # Format error to a somewhat readable format
325
- exc_type, exc_obj, exc_tb = sys.exc_info()
326
- error = str(e)[:400].replace('\'', '').replace('\"', '') + ' | Line: {}'.format(exc_tb.tb_lineno)
327
-
328
- # Log to log table in the database
329
- if self.write_logs_to_mysql:
330
- query = "INSERT INTO `task_execution_log` (reload_id, task_id, log_level, created_at, line_number, message) VALUES ({}, {}, 'CRITICAL', '{}', {}, '{}')".format(self.run_id, self.task_id, now, exc_tb.tb_lineno, error)
331
- self.mysql.raw_query(query, insert=True)
332
- if send_to_teams:
333
- Functions.send_error_to_teams(database=customer, task_number=self.task_id, task_title=taskname)
334
- if breaking:
335
- # Set scheduler status to failed
336
- self.mysql.update('task_scheduler', ['status', 'last_reload', 'last_error_message', 'step_nr'],
337
- ['IDLE', now, 'Failed', 0],
338
- 'WHERE `id` = {}'.format(self.task_id))
339
-
340
- self.mysql.update(table='task_scheduler_log',
341
- columns=['reload_status', 'finished_at'],
342
- values=['Failed', f'{now}'],
343
- filter=f'WHERE `reload_id` = {self.run_id}')
344
- if self.email_after_errors:
345
- self.email_errors(failed=True)
346
- # Remove the temp values from the variables table
347
- self.mysql.raw_query(f'UPDATE `task_variables` SET temp_value = null WHERE task_id = {self.task_id}', insert=True)
348
-
349
- # Start the chained tasks if it there are tasks which should start if this one is failed
350
- self.start_chained_tasks(finished_task_status='FAILED')
351
-
352
- raise Exception(error)
353
-
354
-
355
- def finish_task(self, reload_instant=False, log_limit: typing.Optional[int] = 10000, log_date_limit: datetime.date = None):
356
- """
357
- At the end of the script, write the outcome to the database. Write if the task is finished with or without errors, Email to a contactperson if this variable is given in the
358
- variables table. Also clean up the execution_log table when the number of lines is more than 1000
359
- :param reload_instant: If the task should start again after it's finished
360
- :param log_limit: The maximum number of logs to keep in the database. If the number of logs exceeds this limit, the oldest logs will be deleted.
361
- :param log_date_limit: The date from which logs should be kept. If this is set, logs older than this date will be deleted.
362
- :return:
363
- """
364
- # If reload instant is true, this adds an extra field 'run_instant' to the update query, and sets the value to 1. This makes the task reload immediately after it's finished
365
- field = ['run_instant', 'next_reload'] if reload_instant else []
366
- value = ['1', datetime.datetime.now()] if reload_instant else []
367
- if self.error_count > 0:
368
- self.mysql.update('task_scheduler', ['status', 'last_reload', 'last_error_message', 'step_nr'],
369
- ['IDLE', datetime.datetime.now(), 'FinishedWithErrors', 0],
370
- 'WHERE `id` = {}'.format(self.task_id))
371
- self.mysql.update(table='task_scheduler_log',
372
- columns=['reload_status', 'finished_at'],
373
- values=['FinishedWithErrors', f'{datetime.datetime.now()}'],
374
- filter=f'WHERE `reload_id` = {self.run_id}')
375
- # If the variable self.send_mail_after_errors is set to True, send an email with the number of errors to the given user
376
- if self.email_after_errors:
377
- self.email_errors(failed=False)
378
- else:
379
- self.mysql.update(table='task_scheduler',
380
- columns=['status', 'last_reload', 'last_error_message', 'step_nr', 'stopped_by_user'] + field,
381
- values=['IDLE', datetime.datetime.now(), 'FinishedSucces', 0, 0] + value,
382
- filter='WHERE `id` = {}'.format(self.task_id))
383
-
384
- self.mysql.update(table='task_scheduler_log',
385
- columns=['reload_status', 'finished_at'],
386
- values=['FinishedSuccess', f'{datetime.datetime.now()}'],
387
- filter=f'WHERE `reload_id` = {self.run_id}')
388
-
389
- # Remove the temp values from the variables table
390
- self.mysql.raw_query(f'UPDATE `task_variables` SET temp_value = null WHERE task_id = {self.task_id}', insert=True)
391
-
392
- # Start the new task if it there is a task which should start if this one is finished
393
- self.start_chained_tasks(finished_task_status='SUCCESS')
394
-
395
- if self.write_logs_to_mysql:
396
- # Clean up execution log
397
- # set this date filter above the actual delete filter because of the many uncooperative quotation marks involved in the whole filter
398
- log_date_limit_filter = f"AND created_at >= \'{log_date_limit.strftime('%Y-%m-%d')}\'" if log_date_limit is not None else None
399
- delete_filter = f"WHERE task_id = {self.task_id} " \
400
- f"AND reload_id NOT IN (SELECT reload_id FROM (SELECT reload_id FROM `task_execution_log` WHERE task_id = {self.task_id} " \
401
- f"AND log_level != 'CRITICAL' " \
402
- f"AND log_level != 'ERROR' " \
403
- f"{log_date_limit_filter if log_date_limit_filter is not None else ''} " \
404
- f"ORDER BY created_at DESC {f' LIMIT {log_limit} ' if log_limit is not None else ''}) temp)"
405
-
406
- resp = self.mysql.delete(table="task_execution_log",
407
- filter=delete_filter)
408
- print(resp)
409
-
410
- def start_chained_tasks(self, finished_task_status: str):
411
- filter = f'WHERE start_after_task_id = \'{self.task_id}\' AND start_after_preceding_task = \'{finished_task_status}\''
412
- response = self.mysql.select(table='task_scheduler', selection='id', filter=filter)
413
- if len(response) > 0:
414
- tasks_to_run = [str(task[0]) for task in response]
415
- self.mysql.update(table='task_scheduler', columns=['run_instant'], values=['1'], filter=f'WHERE id IN({",".join(tasks_to_run)})')
416
-
417
- def email_errors(self, failed):
418
- # The mails to email to should be stored in the task_variables table with the variable email_errors_to
419
- email_variable = self.db_variable('email_errors_to')
420
- if email_variable is not None:
421
- email_to = email_variable.split(',')
422
- if isinstance(email_to, list):
423
- # The email_errors_to variable is a simple string. Convert it to a list and add a name because mandrill is asking for it
424
- email_list = []
425
- for i in email_to:
426
- email_list.append({'name': 'BrynQ User', 'mail': i.strip()})
427
- # Set the content of the mail and all other stuff
428
- task = self.mysql.select(table='data_interfaces', selection='title', filter=f'WHERE id = {self.task_id}')[0][0]
429
- finished_at = \
430
- self.mysql.select(table='task_scheduler', selection='last_reload', filter=f'WHERE data_interface_id = {self.task_id}')[0][0]
431
- if failed:
432
- subject = f'Task \'{task}\' has failed'
433
- content = f'Task \'{task}\' with task ID \'{self.task_id}\' failed during its last run and was stopped at {finished_at}. ' \
434
- f'The task is failed. ' \
435
- f'to visit the BrynQ scheduler, click here: <a href="https://app.brynq.com/interfaces/">here</a>. Here you can find the logs and find more information on why this task had failed.'
436
- else:
437
- subject = f'Task \'{task}\' is finished with errors'
438
- content = f'Task \'{task}\' with ID \'{self.task_id}\' has runned and is finished at {finished_at}. ' \
439
- f'The task is finished with {self.error_count} errors. ' \
440
- f'to visit the BrynQ scheduler, click here: <a href="https://app.brynq.com/interfaces/">here</a>. Here you can find the logs and find more information on why this task had some errors.'
441
- MailClient().send_mail(email_to=email_list, subject=subject, content=content, language='EN')
@@ -1,5 +0,0 @@
1
- brynq-sdk-brynq>=1
2
- brynq-sdk-functions>=1
3
- brynq-sdk-mysql>=1
4
- brynq-sdk-mandrill>=1
5
- brynq-sdk-elastic>=2