Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
apscheduler
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ from slack_sdk.errors import SlackApiError
|
|
8 |
import aiojobs
|
9 |
import asyncio
|
10 |
from datetime import datetime, timedelta
|
|
|
|
|
11 |
|
12 |
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
13 |
SLACK_BOT_TOKEN = os.getenv('BOT_USER_OAUTH_TOKEN_HF')
|
@@ -141,11 +143,6 @@ def post_to_slack_create_thread(channel, text, thread_ts=None):
|
|
141 |
return None
|
142 |
|
143 |
#----------------------------------------------------------------------------------------------
|
144 |
-
async def collect_pings():
|
145 |
-
await bot.wait_until_ready()
|
146 |
-
while not bot.is_closed():
|
147 |
-
await aiojobs.create_scheduler().spawn(send_daily_pings())
|
148 |
-
await asyncio.sleep(60)
|
149 |
|
150 |
async def send_daily_pings():
|
151 |
global daily_pings
|
@@ -155,11 +152,6 @@ async def send_daily_pings():
|
|
155 |
await post_to_slack(None, combined_message, SLACK_CHANNEL_ID_TEST, None, None, None)
|
156 |
daily_pings = [] # reset after posting
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
# pings -------------------------------------------------------------------------------------------
|
164 |
|
165 |
async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
@@ -172,15 +164,15 @@ async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
|
172 |
print(f"Error posting to Slack: {e.response['error']}")
|
173 |
|
174 |
|
|
|
|
|
|
|
|
|
|
|
175 |
# runs discord bot in thread = helps avoid blocking calls
|
176 |
-
|
177 |
-
bot.
|
178 |
-
|
179 |
-
def start_bot_thread():
|
180 |
-
loop = asyncio.new_event_loop()
|
181 |
-
asyncio.set_event_loop(loop)
|
182 |
-
loop.run_until_complete(run_bot())
|
183 |
-
threading.Thread(target=start_bot_thread).start()
|
184 |
def greet(name):
|
185 |
return "Hello " + name + "!"
|
186 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
|
|
8 |
import aiojobs
|
9 |
import asyncio
|
10 |
from datetime import datetime, timedelta
|
11 |
+
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
12 |
+
|
13 |
|
14 |
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
15 |
SLACK_BOT_TOKEN = os.getenv('BOT_USER_OAUTH_TOKEN_HF')
|
|
|
143 |
return None
|
144 |
|
145 |
#----------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
async def send_daily_pings():
|
148 |
global daily_pings
|
|
|
152 |
await post_to_slack(None, combined_message, SLACK_CHANNEL_ID_TEST, None, None, None)
|
153 |
daily_pings = [] # reset after posting
|
154 |
|
|
|
|
|
|
|
|
|
|
|
155 |
# pings -------------------------------------------------------------------------------------------
|
156 |
|
157 |
async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
|
|
164 |
print(f"Error posting to Slack: {e.response['error']}")
|
165 |
|
166 |
|
167 |
+
scheduler = AsyncIOScheduler()
|
168 |
+
scheduler.add_job(send_daily_pings, 'interval', minutes=1)
|
169 |
+
scheduler.start()
|
170 |
+
|
171 |
+
|
172 |
# runs discord bot in thread = helps avoid blocking calls
|
173 |
+
def run_bot():
|
174 |
+
bot.run(DISCORD_TOKEN)
|
175 |
+
threading.Thread(target=run_bot).start()
|
|
|
|
|
|
|
|
|
|
|
176 |
def greet(name):
|
177 |
return "Hello " + name + "!"
|
178 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|