fix threading on inactive followers

This commit is contained in:
Believethehype
2024-06-24 09:07:35 +02:00
parent b40467f6c8
commit 3fc15ee114
4 changed files with 32 additions and 20 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import json import json
import os import os
from datetime import timedelta from datetime import timedelta
@@ -26,7 +27,7 @@ Params: None
class DiscoverInactiveFollows(DVMTaskInterface): class DiscoverInactiveFollows(DVMTaskInterface):
KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY KIND: Kind = EventDefinitions.KIND_NIP90_PEOPLE_DISCOVERY
TASK: str = "inactive-followings" TASK: str = "inactive-followings"
FIX_COST: float = 100 FIX_COST: float = 0
client: Client client: Client
dvm_config: DVMConfig dvm_config: DVMConfig
@@ -75,8 +76,9 @@ class DiscoverInactiveFollows(DVMTaskInterface):
# relaylimits.event_max_size(None) # relaylimits.event_max_size(None)
relaylimits = RelayLimits.disable() relaylimits = RelayLimits.disable()
opts = (Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))).relay_limits(relaylimits) opts = (
Options().wait_for_send(False).send_timeout(timedelta(seconds=self.dvm_config.RELAY_TIMEOUT))).relay_limits(
relaylimits)
cli = Client.with_opts(signer, opts) cli = Client.with_opts(signer, opts)
for relay in self.dvm_config.RELAY_LIST: for relay in self.dvm_config.RELAY_LIST:
@@ -92,7 +94,6 @@ class DiscoverInactiveFollows(DVMTaskInterface):
followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3)) followers_filter = Filter().author(PublicKey.parse(options["user"])).kind(Kind(3))
followers = await cli.get_events_of([followers_filter], timedelta(seconds=5)) followers = await cli.get_events_of([followers_filter], timedelta(seconds=5))
if len(followers) > 0: if len(followers) > 0:
result_list = [] result_list = []
newest = 0 newest = 0
@@ -104,7 +105,6 @@ class DiscoverInactiveFollows(DVMTaskInterface):
newest = entry.created_at().as_secs() newest = entry.created_at().as_secs()
best_entry = entry best_entry = entry
print(best_entry.as_json()) print(best_entry.as_json())
print(len(best_entry.tags())) print(len(best_entry.tags()))
print(best_entry.created_at().as_secs()) print(best_entry.created_at().as_secs())
@@ -150,15 +150,14 @@ class DiscoverInactiveFollows(DVMTaskInterface):
begin = 0 begin = 0
# Spawn some threads to speed things up # Spawn some threads to speed things up
while begin < len(followings) - step: while begin < len(followings) - step:
args = [followings, ns, begin, step, not_active_since] t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, step, not_active_since),))
t = Thread(target=scanList, args=args)
threads.append(t) threads.append(t)
begin = begin + step - 1 begin = begin + step - 1
# last to step size # last to step size
missing_scans = (len(followings) - begin) missing_scans = (len(followings) - begin)
args = [followings, ns, begin, missing_scans, not_active_since] t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, missing_scans, not_active_since),))
t = Thread(target=scanList, args=args)
threads.append(t) threads.append(t)
# Start all threads # Start all threads

View File

@@ -1,3 +1,4 @@
import asyncio
import json import json
import os import os
from datetime import timedelta from datetime import timedelta
@@ -148,14 +149,14 @@ class DiscoverNonFollowers(DVMTaskInterface):
# Spawn some threads to speed things up # Spawn some threads to speed things up
while begin < len(followings) - step: while begin < len(followings) - step:
args = [followings, ns, begin, step] args = [followings, ns, begin, step]
t = Thread(target=scanList, args=args) t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, step),))
threads.append(t) threads.append(t)
begin = begin + step - 1 begin = begin + step - 1
# last to step size # last to step size
missing_scans = (len(followings) - begin) missing_scans = (len(followings) - begin)
args = [followings, ns, begin, missing_scans] args = [followings, ns, begin, missing_scans]
t = Thread(target=scanList, args=args) t = Thread(target=asyncio.run, args=(scanList(followings, ns, begin, missing_scans),))
threads.append(t) threads.append(t)
# Start all threads # Start all threads

View File

@@ -37,9 +37,9 @@ async def input_data_file_duration(event, dvm_config, client, start=0, end=0):
return len(input_value) return len(input_value)
if input_type == "url": if input_type == "url":
source_type = check_source_type(input_value)
duration = get_media_duration(input_value) duration = get_media_duration(input_value)
if duration is None: if duration is None:
source_type = check_source_type(input_value)
filename, start, end, type = get_file_start_end_type(input_value, source_type, start, end, True) filename, start, end, type = get_file_start_end_type(input_value, source_type, start, end, True)
if type != "audio" and type != "video": if type != "audio" and type != "video":
return 1 return 1
@@ -79,6 +79,9 @@ async def organize_input_media_data(input_value, input_type, start, end, dvm_con
if type != "audio" and type != "video": if type != "audio" and type != "video":
return filename return filename
try: try:
source_type = check_source_type(input_value)
duration = get_media_duration(input_value)
if duration is None:
# file_reader = AudioReader(filename, ctx=cpu(0), mono=False) # file_reader = AudioReader(filename, ctx=cpu(0), mono=False)
# duration = float(file_reader.duration()) # duration = float(file_reader.duration())
duration = ffmpegio.probe.format_basic(filename)['duration'] duration = ffmpegio.probe.format_basic(filename)['duration']

View File

@@ -8,7 +8,7 @@ import dotenv
from nostr_sdk import Keys from nostr_sdk import Keys
from nostr_dvm.bot import Bot from nostr_dvm.bot import Bot
from nostr_dvm.tasks import textextraction_pdf, convert_media from nostr_dvm.tasks import textextraction_pdf, convert_media, discovery_inactive_follows
from nostr_dvm.utils.admin_utils import AdminConfig from nostr_dvm.utils.admin_utils import AdminConfig
from nostr_dvm.utils.backend_utils import keep_alive from nostr_dvm.utils.backend_utils import keep_alive
from nostr_dvm.utils.definitions import EventDefinitions from nostr_dvm.utils.definitions import EventDefinitions
@@ -55,6 +55,15 @@ def playground():
bot_config.SUPPORTED_DVMS.append(media_bringer) bot_config.SUPPORTED_DVMS.append(media_bringer)
media_bringer.run() media_bringer.run()
admin_config_followers = AdminConfig()
admin_config_followers.UPDATE_PROFILE = True
admin_config_followers.REBROADCAST_NIP65_RELAY_LIST = True
discover_inactive = discovery_inactive_follows.build_example("Those who left",
"discovery_inactive_follows", admin_config_followers)
bot_config.SUPPORTED_DVMS.append(discover_inactive)
discover_inactive.run()
admin_config = AdminConfig() admin_config = AdminConfig()
admin_config.REBROADCAST_NIP65_RELAY_LIST = True admin_config.REBROADCAST_NIP65_RELAY_LIST = True
admin_config.UPDATE_PROFILE = True admin_config.UPDATE_PROFILE = True