Skip to content

Commit

Permalink
fix updating of app status
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonOstrez committed Oct 1, 2023
1 parent 0cec2a4 commit 4713a68
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 53 deletions.
69 changes: 26 additions & 43 deletions pilot/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,23 @@
DB_PORT = os.getenv("DB_PORT")
DB_USER = os.getenv("DB_USER")
DB_PASSWORD = os.getenv("DB_PASSWORD")

TABLES = [
User,
App,
ProjectDescription,
UserStories,
UserTasks,
Architecture,
DevelopmentPlanning,
DevelopmentSteps,
EnvironmentSetup,
Development,
FileSnapshot,
CommandRuns,
UserApps,
UserInputs,
File,
]

def get_created_apps():
return [model_to_dict(app) for app in App.select()]
Expand Down Expand Up @@ -94,16 +110,18 @@ def get_user(user_id=None, email=None):


def save_app(project):
args = project.args
app_status = getattr(project, "current_step", None)

try:
args = project.args
app = App.get(App.id == args['app_id'])
for key, value in args.items():
if key != 'app_id' and value is not None:
setattr(app, key, value)
app.status = project.current_step

app.status = app_status
app.save()
except DoesNotExist:
args = project.args
if args.get('user_id') is not None:
try:
user = get_user(user_id=args['user_id'])
Expand All @@ -119,7 +137,7 @@ def save_app(project):
user=user,
app_type=args.get('app_type'),
name=args.get('name'),
status=project.current_step
status=app_status
)

return app
Expand Down Expand Up @@ -401,44 +419,12 @@ def save_file_description(project, path, name, description):

def create_tables():
with database:
database.create_tables([
User,
App,
ProjectDescription,
UserStories,
UserTasks,
Architecture,
DevelopmentPlanning,
DevelopmentSteps,
EnvironmentSetup,
Development,
FileSnapshot,
CommandRuns,
UserApps,
UserInputs,
File,
])
database.create_tables(TABLES)


def drop_tables():
with database.atomic():
for table in [
User,
App,
ProjectDescription,
UserStories,
UserTasks,
Architecture,
DevelopmentPlanning,
DevelopmentSteps,
EnvironmentSetup,
Development,
FileSnapshot,
CommandRuns,
UserApps,
UserInputs,
File,
]:
for table in TABLES:
if DATABASE_TYPE == "postgres":
sql = f'DROP TABLE IF EXISTS "{table._meta.table_name}" CASCADE'
elif DATABASE_TYPE == "sqlite":
Expand Down Expand Up @@ -484,11 +470,8 @@ def create_database():


def tables_exist():
tables = [User, App, ProjectDescription, UserStories, UserTasks, Architecture, DevelopmentPlanning,
DevelopmentSteps, EnvironmentSetup, Development, FileSnapshot, CommandRuns, UserApps, UserInputs, File]

if DATABASE_TYPE == "postgres":
for table in tables:
for table in TABLES:
try:
database.get_tables().index(table._meta.table_name)
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion pilot/database/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class App(BaseModel):
user = ForeignKeyField(User, backref='apps')
app_type = CharField(null=True)
name = CharField(null=True)
status = CharField(default='started')
status = CharField(null=True)
8 changes: 1 addition & 7 deletions pilot/helpers/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def start(self):
self.architecture = self.architect.get_architecture()

self.developer = Developer(self)
self.developer.set_up_environment();
self.developer.set_up_environment()

self.tech_lead = TechLead(self)
self.development_plan = self.tech_lead.create_development_plan()
Expand Down Expand Up @@ -129,12 +129,6 @@ def start(self):
break
# TODO END

self.developer = Developer(self)
print(json.dumps({
"project_stage": "environment_setup"
}), type='info')
self.developer.set_up_environment()

print(json.dumps({
"project_stage": "coding"
}), type='info')
Expand Down
3 changes: 2 additions & 1 deletion pilot/helpers/agents/Developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from utils.utils import should_execute_step, array_of_objects_to_string, generate_app_data
from helpers.cli import run_command_until_success, execute_command_and_check_cli_response
from const.function_calls import FILTER_OS_TECHNOLOGIES, EXECUTE_COMMANDS, GET_TEST_TYPE, IMPLEMENT_TASK
from database.database import save_progress, get_progress_steps
from database.database import save_progress, get_progress_steps, update_app_status
from utils.utils import get_os_info

ENVIRONMENT_SETUP_STEP = 'environment_setup'
Expand All @@ -27,6 +27,7 @@ def __init__(self, project):

def start_coding(self):
self.project.current_step = 'coding'
update_app_status(self.project.args['app_id'], self.project.current_step)

if self.project.skip_steps is None:
self.project.skip_steps = False if ('skip_until_dev_step' in self.project.args and self.project.args['skip_until_dev_step'] == '0') else True
Expand Down
1 change: 0 additions & 1 deletion pilot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def print_to_external_process(*args, **kwargs):

if 'type' not in kwargs:
kwargs['type'] = 'verbose'
return
elif kwargs['type'] == MESSAGE_TYPE['local']:
local_print(*args, **kwargs)
return
Expand Down
1 change: 1 addition & 0 deletions pilot/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_arguments():

arguments['app_type'] = app.app_type
arguments['name'] = app.name
arguments['step'] = app.status
# Add any other fields from the App model you wish to include

print(green_bold('\n------------------ LOADING PROJECT ----------------------'))
Expand Down

0 comments on commit 4713a68

Please sign in to comment.