Merge pull request #1078 from dod-ccpo/env-beat-schedule
Add a beat processing schedule for environment provisioning jobs.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import text, func, or_
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
from typing import List
|
||||
from uuid import UUID
|
||||
@@ -130,7 +130,7 @@ class Environments(object):
|
||||
results = (
|
||||
cls.base_provision_query(now)
|
||||
.filter(Environment.cloud_id != None)
|
||||
.filter(Environment.root_user_info == text("'null'"))
|
||||
.filter(Environment.root_user_info == None)
|
||||
).all()
|
||||
return [id_ for id_, in results]
|
||||
|
||||
@@ -143,7 +143,7 @@ class Environments(object):
|
||||
results = (
|
||||
cls.base_provision_query(now)
|
||||
.filter(Environment.cloud_id != None)
|
||||
.filter(Environment.root_user_info != text("'null'"))
|
||||
.filter(Environment.baseline_info == text("'null'"))
|
||||
.filter(Environment.root_user_info != None)
|
||||
.filter(Environment.baseline_info == None)
|
||||
).all()
|
||||
return [id_ for id_, in results]
|
||||
|
@@ -26,8 +26,8 @@ class Environment(
|
||||
creator = relationship("User")
|
||||
|
||||
cloud_id = Column(String)
|
||||
root_user_info = Column(JSONB)
|
||||
baseline_info = Column(JSONB)
|
||||
root_user_info = Column(JSONB(none_as_null=True))
|
||||
baseline_info = Column(JSONB(none_as_null=True))
|
||||
|
||||
claimed_until = Column(TIMESTAMP(timezone=True))
|
||||
|
||||
@@ -68,6 +68,10 @@ class Environment(
|
||||
else:
|
||||
return self.ProvisioningStatus.COMPLETED
|
||||
|
||||
@property
|
||||
def is_pending(self):
|
||||
return self.provisioning_status == self.ProvisioningStatus.PENDING
|
||||
|
||||
def __repr__(self):
|
||||
return "<Environment(name='{}', num_users='{}', application='{}', portfolio='{}', id='{}')>".format(
|
||||
self.name,
|
||||
|
@@ -47,3 +47,4 @@ def claim_for_update(resource, minutes=30):
|
||||
db.session.query(Model).filter(Model.id == resource.id).filter(
|
||||
Model.claimed_until != None
|
||||
).update({"claimed_until": None}, synchronize_session="fetch")
|
||||
db.session.commit()
|
||||
|
@@ -5,7 +5,20 @@ celery = Celery(__name__)
|
||||
|
||||
def update_celery(celery, app):
|
||||
celery.conf.update(app.config)
|
||||
celery.conf.CELERYBEAT_SCHEDULE = {}
|
||||
celery.conf.CELERYBEAT_SCHEDULE = {
|
||||
"beat-dispatch_create_environment": {
|
||||
"task": "atst.jobs.dispatch_create_environment",
|
||||
"schedule": 60,
|
||||
},
|
||||
"beat-dispatch_create_atat_admin_user": {
|
||||
"task": "atst.jobs.dispatch_create_atat_admin_user",
|
||||
"schedule": 60,
|
||||
},
|
||||
"beat-dispatch_create_environment_baseline": {
|
||||
"task": "atst.jobs.dispatch_create_environment_baseline",
|
||||
"schedule": 60,
|
||||
},
|
||||
}
|
||||
|
||||
class ContextTask(celery.Task):
|
||||
def __call__(self, *args, **kwargs):
|
||||
|
@@ -25,6 +25,7 @@ def get_environments_obj_for_app(application):
|
||||
env_data = {
|
||||
"id": env.id,
|
||||
"name": env.name,
|
||||
"pending": env.is_pending,
|
||||
"edit_form": EditEnvironmentForm(obj=env),
|
||||
"member_count": len(env.roles),
|
||||
"members": [env_role.application_role.user_name for env_role in env.roles],
|
||||
|
Reference in New Issue
Block a user