-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
223 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/discovery-provider/src/tasks/publish_scheduled_releases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from datetime import datetime, timedelta | ||
from datetime import datetime | ||
|
||
from src.models.tracks.track import Track | ||
|
||
from src.tasks.celery_app import celery | ||
from src.utils.structured_logger import StructuredLogger, log_duration | ||
from src.utils.web3_provider import get_eth_web3 | ||
|
||
logger = StructuredLogger(__name__) | ||
web3 = get_eth_web3() | ||
publish_scheduled_releases_cursor_key = "publish_scheduled_releases_cursor" | ||
batch_size = 1000 | ||
|
||
|
||
def convert_timestamp(release_date_str): | ||
parts = release_date_str.split(" ") | ||
time_zone_offset = parts[-1] # Should be "GMT-0700" in your example | ||
|
||
# Create a datetime object without the time zone offset | ||
date_str_no_offset = " ".join(parts[:-1]) | ||
date_time = datetime.strptime(date_str_no_offset, "%a %b %d %Y %H:%M:%S") | ||
|
||
# Extract the offset values (hours and minutes) | ||
hours_offset = int(time_zone_offset[4:6]) | ||
minutes_offset = int(time_zone_offset[6:]) | ||
|
||
# Calculate the time zone offset as a timedelta | ||
offset = timedelta(hours=hours_offset, minutes=minutes_offset) | ||
|
||
# Adjust the datetime using the offset | ||
adjusted_datetime = date_time - offset | ||
|
||
# Convert the adjusted datetime to an epoch timestamp | ||
epoch_timestamp = int(adjusted_datetime.timestamp()) | ||
return epoch_timestamp | ||
|
||
|
||
@log_duration(logger) | ||
def _publish_scheduled_releases(session, redis): | ||
latest_block = web3.eth.get_block("latest") | ||
current_timestamp = latest_block.timestamp | ||
previous_cursor = redis.get(publish_scheduled_releases_cursor_key) | ||
if not previous_cursor: | ||
previous_cursor = datetime.min | ||
|
||
candidate_tracks = ( | ||
session.query(Track) | ||
.filter( | ||
Track.is_unlisted, | ||
Track.release_date.isnot(None), # Filter for non-null release_date | ||
Track.created_at >= previous_cursor, | ||
) | ||
.order_by(Track.created_at.asc()) | ||
.limit(batch_size) | ||
.all() | ||
) | ||
# convert release date to utc | ||
for candidate_track in candidate_tracks: | ||
unix_time = convert_timestamp(candidate_track.release_date) | ||
release_date_day = datetime.fromtimestamp(unix_time).date() | ||
candidate_created_at_day = candidate_track.created_at.date() | ||
|
||
if ( | ||
current_timestamp >= unix_time | ||
and release_date_day > candidate_created_at_day | ||
): | ||
candidate_track.is_unlisted = False | ||
|
||
if candidate_tracks: | ||
redis.set( | ||
publish_scheduled_releases_cursor_key, candidate_tracks[-1].created_at | ||
) | ||
return | ||
|
||
|
||
# ####### CELERY TASKS ####### # | ||
@celery.task(name="publish_scheduled_releases", bind=True) | ||
def publish_scheduled_releases(self): | ||
redis = publish_scheduled_releases.redis | ||
db = publish_scheduled_releases.db | ||
|
||
# Define lock acquired boolean | ||
have_lock = False | ||
# Define redis lock object | ||
update_lock = redis.lock( | ||
"publish_scheduled_releases_lock", blocking_timeout=25, timeout=600 | ||
) | ||
try: | ||
have_lock = update_lock.acquire(blocking=False) | ||
if have_lock: | ||
with db.scoped_session() as session: | ||
_publish_scheduled_releases(session, redis) | ||
|
||
else: | ||
logger.info("Failed to acquire lock") | ||
except Exception as e: | ||
logger.error(f"ERROR caching node info {e}") | ||
raise e | ||
finally: | ||
if have_lock: | ||
update_lock.release() |
5 changes: 5 additions & 0 deletions
5
packages/mobile/ios/AudiusReactNative.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.