Skip to content

Commit

Permalink
Version 0.10.0 (#14)
Browse files Browse the repository at this point in the history
* #6 Multiple tasks in the same flow

* #8 #9 Improve stopping of running processes and modify the execute_tasks function to a method of the FluxosExecutor class

* #12 Interrupt pending flows and restart them programmatically

* #10 Create new screen for Flow information
  • Loading branch information
nascin authored Dec 18, 2023
1 parent 2b60b13 commit ca1d655
Show file tree
Hide file tree
Showing 24 changed files with 1,428 additions and 664 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Write the following code in the fluxo1.py file to create a basic flow with a tas
#### python_files/fluxo1.py:

```
from fluxo.fluxo_core.fluxo import Fluxo
from fluxo.fluxo_core.flow import Flow
from fluxo.fluxo_core.task import Task
fluxo = Fluxo(name='Fluxo 1', interval={'minutes': 1, 'at': ':00'})
flow = Flow(name='My Flow 1', interval={'minutes': 1, 'at': ':00'})
@Task('Task 1', fluxo=fluxo)
async def My_func1():
print('My_func1 executed!')
@Task('My Task 1', flow=flow)
async def My_func():
print('My_func executed!')
```

### 4 - Finally, start the program with the command below:
Expand Down
10 changes: 5 additions & 5 deletions fluxo/fluxo_core/database/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@dataclass
class App:
class ModelApp:
'''
Represents an application status in database
Expand Down Expand Up @@ -49,7 +49,7 @@ def save(self):

conn.close()

return App.get()
return ModelApp.get()

@staticmethod
def update(id: int, active: bool):
Expand All @@ -75,7 +75,7 @@ def update(id: int, active: bool):
conn.commit()
conn.close()

return App.get()
return ModelApp.get()

@staticmethod
def get(id: int = 1):
Expand All @@ -94,14 +94,14 @@ def get(id: int = 1):
data = cursor.fetchone()
conn.close()
if data:
return App(*data)
return ModelApp(*data)
else:
return None


def __repr__(self) -> str:
'''
Returns a string representation of the 'App' instance.
Returns a string representation of the 'ModelApp' instance.
'''
return f'''
id: {self.id},
Expand Down
78 changes: 52 additions & 26 deletions fluxo/fluxo_core/database/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sqlite3
from fluxo.settings import Db
from fluxo.fluxo_core.flows_executor import logging


def _verify_if_db_exists(path_db: str = Db.PATH):
Expand All @@ -10,74 +11,99 @@ def _verify_if_db_exists(path_db: str = Db.PATH):
Parameters:
- path_db (str): The path to the database file. Defaults to the path specified in the
`settings_db.PATH` variable.
`Db.PATH` variable.
Returns:
None
None
'''
if not os.path.exists(path_db):
create_db(path_db)


def create_db(path_db: str):
'''
Creates a SQLite database at the specified path with two tables: 'TB_Fluxo' and 'TB_Task'.
If the tables do not exist, it creates them along with their respective columns.
Creates a SQLite database at the specified path. If the tables do not exist,
it creates them along with their respective columns.
Parameters:
- path_db (str): The path to the SQLite database file.
Return:
None
'''
# Database connection
conn = sqlite3.connect(path_db)

# Create TB_Fluxo table
try:
# Database connection
conn = sqlite3.connect(path_db)

# Create TB_Flow table
conn.execute('''
CREATE TABLE IF NOT EXISTS TB_Fluxo (
CREATE TABLE IF NOT EXISTS TB_Flow (
id INTEGER PRIMARY KEY,
name TEXT,
date_of_creation DATE,
interval TEXT,
active BOOLEAN
active BOOLEAN,
list_names_tasks TEXT, -- Storing the list as a JSON string
running BOOLEAN,
running_process TEXT -- Storing the list as a JSON string
)
''')
print('++ TB_Fluxo table created successfully.')
except Exception as err:
raise Exception(f'++ Error creating TB_Fluxo table: {err}')
logging.info('TB_Flow table created successfully')

# Create TB_Task table
try:
# Create TB_Task table
conn.execute('''
CREATE TABLE IF NOT EXISTS TB_Task (
id INTEGER PRIMARY KEY,
name TEXT,
execution_date DATE,
fluxo_id INTEGER,
flow_id INTEGER,
start_time DATE,
end_time DATE,
error TEXT,
FOREIGN KEY (fluxo_id) REFERENCES TB_Fluxo(id) ON DELETE CASCADE
error TEXT
)
''')
print('++ TB_Task table created successfully.')
except Exception as err:
raise Exception(f'++ Error creating TB_Task table: {err}')

# Create TB_App table
try:
logging.info('TB_Task table created successfully')

# Create TB_LogExecutionFlow table
conn.execute('''
CREATE TABLE TB_LogExecutionFlow (
id INTEGER PRIMARY KEY,
name TEXT,
date_of_creation DATETIME,
start_time DATETIME,
end_time DATETIME,
id_flow INTEGER,
ids_task TEXT, -- Storing the list as a JSON string
ids_error_task TEXT -- Storing the list as a JSON string
)
''')
logging.info('TB_LogExecutionFlow table created successfully')

# Create TB_App table
conn.execute('''
CREATE TABLE IF NOT EXISTS TB_App (
id INTEGER PRIMARY KEY,
active BOOLEAN,
active_since DATE
)
''')
print('++ TB_App table created successfully.')
logging.info('TB_App table created successfully')


except Exception as err:
raise Exception(f'++ Error creating TB_App table: {err}')
# Log the error
logging.error(f'Error during database creation: {err}')

# Close the connection if open
if 'conn' in locals() and conn is not None:
conn.close()

# Delete the file if it exists
if os.path.exists(path_db):
os.remove(path_db)

# Raise the exception to propagate the error
raise err

finally:
# Committing the changes
Expand Down
Loading

0 comments on commit ca1d655

Please sign in to comment.