feat: switch all timezone naive datetimes to timezone aware
This commit is contained in:
parent
41fc0a73a5
commit
e22abb383c
30 changed files with 322 additions and 226 deletions
|
@ -1,44 +1,48 @@
|
|||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from traceback import TracebackException
|
||||
from typing import Type
|
||||
|
||||
from app import app
|
||||
from app.cli import _SubparserType, BaseCliHandler
|
||||
from app.cli import BaseCliHandler, _SubparserType
|
||||
from app.extensions import db
|
||||
from app.models.activity import Activity
|
||||
from app.models.automation import Automation, AutomationState, AutomationLogs
|
||||
from app.models.automation import Automation, AutomationLogs, AutomationState
|
||||
from app.terraform import BaseAutomation
|
||||
from app.terraform.alarms.eotk_aws import AlarmEotkAwsAutomation
|
||||
from app.terraform.alarms.proxy_azure_cdn import AlarmProxyAzureCdnAutomation
|
||||
from app.terraform.alarms.proxy_cloudfront import \
|
||||
AlarmProxyCloudfrontAutomation
|
||||
from app.terraform.alarms.proxy_http_status import \
|
||||
AlarmProxyHTTPStatusAutomation
|
||||
from app.terraform.alarms.smart_aws import AlarmSmartAwsAutomation
|
||||
from app.terraform.block.block_blocky import BlockBlockyAutomation
|
||||
from app.terraform.block.block_scriptzteam import \
|
||||
BlockBridgeScriptzteamAutomation
|
||||
from app.terraform.block.bridge_github import BlockBridgeGitHubAutomation
|
||||
from app.terraform.block.bridge_gitlab import BlockBridgeGitlabAutomation
|
||||
from app.terraform.block.bridge_roskomsvoboda import BlockBridgeRoskomsvobodaAutomation
|
||||
from app.terraform.block.block_scriptzteam import BlockBridgeScriptzteamAutomation
|
||||
from app.terraform.block.bridge_roskomsvoboda import \
|
||||
BlockBridgeRoskomsvobodaAutomation
|
||||
from app.terraform.block_external import BlockExternalAutomation
|
||||
from app.terraform.block_ooni import BlockOONIAutomation
|
||||
from app.terraform.block_roskomsvoboda import BlockRoskomsvobodaAutomation
|
||||
from app.terraform.bridge.meta import BridgeMetaAutomation
|
||||
from app.terraform.eotk.aws import EotkAWSAutomation
|
||||
from app.terraform.alarms.eotk_aws import AlarmEotkAwsAutomation
|
||||
from app.terraform.alarms.proxy_azure_cdn import AlarmProxyAzureCdnAutomation
|
||||
from app.terraform.alarms.proxy_cloudfront import AlarmProxyCloudfrontAutomation
|
||||
from app.terraform.alarms.proxy_http_status import AlarmProxyHTTPStatusAutomation
|
||||
from app.terraform.alarms.smart_aws import AlarmSmartAwsAutomation
|
||||
from app.terraform.bridge.aws import BridgeAWSAutomation
|
||||
from app.terraform.bridge.gandi import BridgeGandiAutomation
|
||||
from app.terraform.bridge.hcloud import BridgeHcloudAutomation
|
||||
from app.terraform.bridge.meta import BridgeMetaAutomation
|
||||
from app.terraform.bridge.ovh import BridgeOvhAutomation
|
||||
from app.terraform.eotk.aws import EotkAWSAutomation
|
||||
from app.terraform.list.github import ListGithubAutomation
|
||||
from app.terraform.list.gitlab import ListGitlabAutomation
|
||||
from app.terraform.list.http_post import ListHttpPostAutomation
|
||||
from app.terraform.list.s3 import ListS3Automation
|
||||
from app.terraform.proxy.meta import ProxyMetaAutomation
|
||||
from app.terraform.proxy.azure_cdn import ProxyAzureCdnAutomation
|
||||
from app.terraform.proxy.cloudfront import ProxyCloudfrontAutomation
|
||||
from app.terraform.proxy.fastly import ProxyFastlyAutomation
|
||||
from app.terraform.proxy.meta import ProxyMetaAutomation
|
||||
from app.terraform.static.aws import StaticAWSAutomation
|
||||
from app.terraform.static.meta import StaticMetaAutomation
|
||||
|
||||
|
@ -108,7 +112,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
automation.description = job_cls.description
|
||||
automation.enabled = False
|
||||
automation.next_is_full = False
|
||||
automation.added = datetime.datetime.utcnow()
|
||||
automation.added = datetime.now(tz=timezone.utc)
|
||||
automation.updated = automation.added
|
||||
db.session.add(automation)
|
||||
db.session.commit()
|
||||
|
@ -117,7 +121,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
logging.warning("Not running an already running automation")
|
||||
return
|
||||
if not ignore_schedule and not force:
|
||||
if automation.next_run is not None and automation.next_run > datetime.datetime.utcnow():
|
||||
if automation.next_run is not None and automation.next_run > datetime.now(tz=timezone.utc):
|
||||
logging.warning("Not time to run this job yet")
|
||||
return
|
||||
if not automation.enabled and not force:
|
||||
|
@ -145,7 +149,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
logs = "\n".join(trace.format())
|
||||
if job is not None and success:
|
||||
automation.state = AutomationState.IDLE
|
||||
automation.next_run = datetime.datetime.utcnow() + datetime.timedelta(
|
||||
automation.next_run = datetime.now(tz=timezone.utc) + timedelta(
|
||||
minutes=getattr(job, "frequency", 7))
|
||||
if 'TERRAFORM_DIRECTORY' not in app.config and working_dir is not None:
|
||||
# We used a temporary working directory
|
||||
|
@ -168,8 +172,8 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
automation.next_run = None
|
||||
log = AutomationLogs()
|
||||
log.automation_id = automation.id
|
||||
log.added = datetime.datetime.utcnow()
|
||||
log.updated = datetime.datetime.utcnow()
|
||||
log.added = datetime.now(tz=timezone.utc)
|
||||
log.updated = datetime.now(tz=timezone.utc)
|
||||
log.logs = str(logs)
|
||||
db.session.add(log)
|
||||
db.session.commit()
|
||||
|
@ -182,7 +186,7 @@ def run_job(job_cls: Type[BaseAutomation], *,
|
|||
)
|
||||
db.session.add(activity)
|
||||
activity.notify() # Notify before commit because the failure occurred even if we can't commit.
|
||||
automation.last_run = datetime.datetime.utcnow()
|
||||
automation.last_run = datetime.now(tz=timezone.utc)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue