Skip to content

Commit

Permalink
v0.14.0 (#31)
Browse files Browse the repository at this point in the history
* #27 Change the loop in the schedule's

* Version dinamic

* #21 Create class for execution intervals

* #29 Error redirecting page
  • Loading branch information
nascin authored Dec 28, 2023
1 parent 3a33856 commit 7a3617a
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 25 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Write the following code in the fluxo1.py file to create a basic flow with a tas
#### python_files/flow1.py:

```
from fluxo import Flow
from fluxo import Task
from fluxo import Flow, Task, Minutes
flow = Flow(name='My Flow 1', interval={'minutes': 1, 'at': ':00'})
interval = Minutes(1, 30).format()
flow = Flow(name='My Flow 1', interval=interval)
@Task('My Task 1', flow=flow)
async def My_func():
Expand All @@ -57,4 +57,4 @@ python -m fluxo.init_server
http://127.0.0.1:8080
```

![Logo Fluxo](https://firebasestorage.googleapis.com/v0/b/teste-nascin-cripto.appspot.com/o/Fluxo.png?alt=media&token=9a5d971f-8180-4c0f-a774-332a13d3f5c4)
![Logo Fluxo](https://firebasestorage.googleapis.com/v0/b/teste-nascin-cripto.appspot.com/o/fluxo-v0.14.0.png?alt=media&token=c6ac9ac9-d272-4312-be1b-219f409095e1)
12 changes: 11 additions & 1 deletion fluxo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
from fluxo.settings import AppSettings

from fluxo.fluxo_core.flow import Flow
from fluxo.fluxo_core.task import Task
from fluxo.fluxo_core.task import Task

from fluxo.fluxo_core.intervals import (
Minutes,
Hours,
Days
)

__version__ = AppSettings.VERSION
6 changes: 3 additions & 3 deletions fluxo/fluxo_core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Flow:
Example:
```
from fluxo import Flow
from fluxo import Task
from fluxo import Flow, Task, Minutes
flow = Flow(name='My Flow 1', interval={'minutes': 1, 'at': ':00'})
interval = Minutes(1, 30).format()
flow = Flow(name='My Flow 1', interval=interval)
@Task('My Task 1', flow=flow)
async def My_func():
Expand Down
2 changes: 2 additions & 0 deletions fluxo/fluxo_core/flows_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import schedule
import signal
from time import sleep
from typing import List, Optional
from fluxo.settings import PathFilesPython, Db
from fluxo.uttils import current_time_formatted
Expand Down Expand Up @@ -364,6 +365,7 @@ def _schedule_async_tasks():
while condition:
try:
schedule.run_pending()
sleep(1)
except KeyboardInterrupt:
for job in jobs_pending:
schedule.cancel_job(job)
Expand Down
123 changes: 123 additions & 0 deletions fluxo/fluxo_core/intervals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@


class Minutes:
'''
A class representing time in minutes and seconds.
Args:
- minutes (int): The number of minutes.
- seconds (int): The number of seconds (0 to 59).
Attributes:
- minutes (int): The number of minutes.
- seconds (str): The formatted representation of seconds as a two-digit string.
Methods:
- format(): Returns a dictionary with 'minutes' and 'at' keys representing the time.
Example:
>>> time = Minutes(5, 30)
>>> time.format()
{'minutes': 5, 'at': ':30'}
'''
def __init__(self, minutes: int, seconds: int) -> None:
if not isinstance(minutes, int):
raise ValueError("Minutes must be an integer.")

if not (isinstance(seconds, int) and 0 <= seconds <= 59):
raise ValueError("Seconds must be a int representing a two-digit integer between 0 and 59.")

if not seconds >= 10:
seconds = ''.join(['0',str(seconds)])

self.minutes = minutes
self.seconds = seconds

def format(self):
return {'minutes': self.minutes, 'at': f':{self.seconds}'}


class Hours:
'''
A class representing time in hours and minutes.
Args:
- hours (int): The number of hours.
- minutes (int): The number of minutes (0 to 59).
Attributes:
- hours (int): The number of hours.
- minutes (str): The formatted representation of minutes as a two-digit string.
Methods:
- format(): Returns a dictionary with 'hours' and 'at' keys representing the time.
Example:
>>> time = Hours(3, 45)
>>> time.format()
{'hours': 3, 'at': ':45'}
'''

def __init__(self, hours: int, minutes: int) -> None:
if not isinstance(hours, int):
raise ValueError("Hours must be an integer.")

if not (isinstance(minutes, int) and 0 <= minutes <= 59):
raise ValueError("Minutes must be a int representing a two-digit integer between 0 and 59.")

if not minutes >= 10:
minutes = ''.join(['0',str(minutes)])

self.hours = hours
self.minutes = minutes

def format(self):
return {'hours': self.hours, 'at': f':{self.minutes}'}


class Days:
'''
A class representing time in days, hours, and minutes.
Args:
- days (int): The number of days.
- hours_minutes (tuple): A tuple representing hours and minutes (0 to 23 and 0 to 59, respectively).
Attributes:
- days (int): The number of days.
- hours (str): The formatted representation of hours as a two-digit string.
- minutes (str): The formatted representation of minutes as a two-digit string.
Methods:
- format(): Returns a dictionary with 'days' and 'at' keys representing the time.
Example:
>>> time = Days(5, (18, 30))
>>> time.format()
{'days': 5, 'at': '18:30'}
'''
def __init__(self, days: int, hours_minutes: tuple) -> None:
hours = hours_minutes[0]
minutes = hours_minutes[1]

if not isinstance(days, int):
raise ValueError("Days must be an integer.")

if not (isinstance(hours_minutes, tuple) and 0 <= hours <= 23 and 0 <= minutes <= 59):
raise ValueError("Hours and Minutes must be a tuple representing hours and minutes between (0,0) and (23,59).")

if not (isinstance(hours, int) and isinstance(minutes, int)):
raise ValueError('Values in tuple must be integer.')

if not hours >= 10:
hours = ''.join(['0',str(hours)])

if not minutes >= 10:
minutes = ''.join(['0',str(minutes)])

self.days = days
self.hours = hours
self.minutes = minutes

def format(self):
return {'days': self.days, 'at': f'{self.hours}:{self.minutes}'}
6 changes: 3 additions & 3 deletions fluxo/fluxo_core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Task:
Example:
```
from fluxo import Flow
from fluxo import Task
from fluxo import Flow, Task, Minutes
flow = Flow(name='My Flow 1', interval={'minutes': 1, 'at': ':00'})
interval = Minutes(1, 30).format()
flow = Flow(name='My Flow 1', interval=interval)
@Task('My Task 1', flow=flow)
async def My_func():
Expand Down
2 changes: 2 additions & 0 deletions fluxo/fluxo_server/screens/flow_execution/flow_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ async def _load_log_flow(self):
)
await self.update_async()

self.page.session.set('log_flow_id', self.log_flow_id)

async def did_mount_async(self):
self.task_load_log_flow = asyncio.create_task(self._load_log_flow())

Expand Down
11 changes: 2 additions & 9 deletions fluxo/fluxo_server/screens/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,8 @@ async def _load_attributes_task(self):
await self.update_async()

async def iconbutton_go_back(self, e):
list_log_flow = ModelLogExecutionFlow.get_all()
for log_flow in list_log_flow:
if log_flow.ids_task:
if int(self.task_id) in log_flow.ids_task:
await self.page.go_async(f'flow-execution/{log_flow.id}')
else:
task = ModelTask.get_by_id(int(self.task_id))
log_flow_endtime_is_none = ModelLogExecutionFlow.get_by_idflow_and_endtime_is_none(task.flow_id)
await self.page.go_async(f'flow-execution/{log_flow_endtime_is_none.id}')
log_flow_id = self.page.session.get('log_flow_id')
await self.page.go_async(f'flow-execution/{log_flow_id}')

async def did_mount_async(self):
self.task_load_attributes_task = asyncio.create_task(self._load_attributes_task())
Expand Down
2 changes: 1 addition & 1 deletion fluxo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AppSettings:
'''Configurações da aplicação Fluxo'''
VERSION = 'v0.13.4'
VERSION = 'v0.14.0'
PORT = 8080
ASSETS_DIR = 'fluxo_server/assets'

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"

[project]
name = "fluxo"
version = "0.13.4"
version = "0.14.0"

authors = [
{ name="Mailson Náscin", email="[email protected]" },
]
description = "Simple data flow with execution in separate threads and easy scheduling configuration."
readme = "README.md"
requires-python = ">=3.11"
keywords = ["fluxo", "data", "scheduler"]
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from setuptools import setup, find_packages


setup(
name='fluxo',
version='0.13.4',
packages=find_packages(),
package_data={
'': ['fluxo_server/assets/**/*'],
Expand Down

0 comments on commit 7a3617a

Please sign in to comment.