Skip to content

Commit fec8dea

Browse files
authored
Merge pull request #425 from MODSetter/dev
fix: celery_app path and gmail indexing
2 parents 4fc12c0 + 0e6669a commit fec8dea

File tree

9 files changed

+61
-34
lines changed

9 files changed

+61
-34
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ representative at an online or offline event.
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6262
reported to the community leaders responsible for enforcement at
63-
vermarohanfinal@gmail.com.
63+
rohan@surfsense.com.
6464
All complaints will be reviewed and investigated promptly and fairly.
6565

6666
All community leaders are obligated to respect the privacy and security of the

surfsense_backend/app/connectors/google_gmail_connector.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,23 +227,42 @@ async def get_message_details(
227227
async def get_recent_messages(
228228
self,
229229
max_results: int = 50,
230-
days_back: int = 30,
230+
start_date: str | None = None,
231+
end_date: str | None = None,
231232
) -> tuple[list[dict[str, Any]], str | None]:
232233
"""
233-
Fetch recent messages from Gmail within specified days.
234+
Fetch recent messages from Gmail within specified date range.
234235
Args:
235236
max_results: Maximum number of messages to fetch (default: 50)
236-
days_back: Number of days to look back (default: 30)
237+
start_date: Start date in YYYY-MM-DD format (default: 30 days ago)
238+
end_date: End date in YYYY-MM-DD format (default: today)
237239
Returns:
238240
Tuple containing (messages list with details, error message or None)
239241
"""
240242
try:
241-
# Calculate date query
242243
from datetime import datetime, timedelta
243244

244-
cutoff_date = datetime.now() - timedelta(days=days_back)
245-
date_query = cutoff_date.strftime("%Y/%m/%d")
246-
query = f"after:{date_query}"
245+
# Build date query
246+
query_parts = []
247+
248+
if start_date:
249+
# Parse start_date from YYYY-MM-DD to Gmail query format YYYY/MM/DD
250+
start_dt = datetime.strptime(start_date, "%Y-%m-%d")
251+
start_query = start_dt.strftime("%Y/%m/%d")
252+
query_parts.append(f"after:{start_query}")
253+
else:
254+
# Default to 30 days ago
255+
cutoff_date = datetime.now() - timedelta(days=30)
256+
date_query = cutoff_date.strftime("%Y/%m/%d")
257+
query_parts.append(f"after:{date_query}")
258+
259+
if end_date:
260+
# Parse end_date from YYYY-MM-DD to Gmail query format YYYY/MM/DD
261+
end_dt = datetime.strptime(end_date, "%Y-%m-%d")
262+
end_query = end_dt.strftime("%Y/%m/%d")
263+
query_parts.append(f"before:{end_query}")
264+
265+
query = " ".join(query_parts)
247266

248267
# Get messages list
249268
messages_list, error = await self.get_messages_list(

surfsense_backend/app/routes/search_source_connectors_routes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,14 +1250,22 @@ async def run_google_gmail_indexing(
12501250
):
12511251
"""Runs the Google Gmail indexing task and updates the timestamp."""
12521252
try:
1253+
# Convert days_back to start_date string in YYYY-MM-DD format
1254+
from datetime import datetime, timedelta
1255+
1256+
start_date_obj = datetime.now() - timedelta(days=days_back)
1257+
start_date = start_date_obj.strftime("%Y-%m-%d")
1258+
end_date = None # No end date, index up to current time
1259+
12531260
indexed_count, error_message = await index_google_gmail_messages(
12541261
session,
12551262
connector_id,
12561263
search_space_id,
12571264
user_id,
1258-
max_messages,
1259-
days_back,
1265+
start_date=start_date,
1266+
end_date=end_date,
12601267
update_last_indexed=False,
1268+
max_messages=max_messages,
12611269
)
12621270
if error_message:
12631271
logger.error(

surfsense_backend/app/tasks/celery_tasks/connector_tasks.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,27 @@ async def _index_google_gmail_messages(
445445
end_date: str,
446446
):
447447
"""Index Google Gmail messages with new session."""
448+
from datetime import datetime
449+
448450
from app.routes.search_source_connectors_routes import (
449451
run_google_gmail_indexing,
450452
)
451453

452-
# Parse dates to get max_messages and days_back
453-
# For now, we'll use default values
454+
# Parse dates to calculate days_back
454455
max_messages = 100
455-
days_back = 30
456+
days_back = 30 # Default
457+
458+
if start_date:
459+
try:
460+
# Parse start_date (format: YYYY-MM-DD)
461+
start_dt = datetime.strptime(start_date, "%Y-%m-%d")
462+
# Calculate days back from now
463+
days_back = (datetime.now() - start_dt).days
464+
# Ensure at least 1 day
465+
days_back = max(1, days_back)
466+
except ValueError:
467+
# If parsing fails, use default
468+
days_back = 30
456469

457470
async with get_celery_session_maker()() as session:
458471
await run_google_gmail_indexing(

surfsense_backend/app/tasks/connector_indexers/google_gmail_indexer.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def index_google_gmail_messages(
4040
start_date: str | None = None,
4141
end_date: str | None = None,
4242
update_last_indexed: bool = True,
43-
max_messages: int = 100,
43+
max_messages: int = 1000,
4444
) -> tuple[int, str]:
4545
"""
4646
Index Gmail messages for a specific connector.
@@ -60,14 +60,6 @@ async def index_google_gmail_messages(
6060
"""
6161
task_logger = TaskLoggingService(session, search_space_id)
6262

63-
# Calculate days back based on start_date
64-
if start_date:
65-
try:
66-
start_date_obj = datetime.strptime(start_date, "%Y-%m-%d")
67-
days_back = (datetime.now() - start_date_obj).days
68-
except ValueError:
69-
days_back = 30 # Default to 30 days if start_date is invalid
70-
7163
# Log task start
7264
log_entry = await task_logger.log_task_start(
7365
task_name="google_gmail_messages_indexing",
@@ -77,7 +69,8 @@ async def index_google_gmail_messages(
7769
"connector_id": connector_id,
7870
"user_id": str(user_id),
7971
"max_messages": max_messages,
80-
"days_back": days_back,
72+
"start_date": start_date,
73+
"end_date": end_date,
8174
},
8275
)
8376

@@ -135,7 +128,7 @@ async def index_google_gmail_messages(
135128
# Fetch recent Google gmail messages
136129
logger.info(f"Fetching recent emails for connector {connector_id}")
137130
messages, error = await gmail_connector.get_recent_messages(
138-
max_results=max_messages, days_back=days_back
131+
max_results=max_messages, start_date=start_date, end_date=end_date
139132
)
140133

141134
if error:

surfsense_backend/celery_worker.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
"""Celery worker startup script."""
22

3-
import os
4-
import sys
5-
6-
# Add the app directory to the Python path
7-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "app"))
8-
93
from app.celery_app import celery_app
104

115
if __name__ == "__main__":

surfsense_web/app/(home)/privacy/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default function PrivacyPolicy() {
181181
contact us at:
182182
</p>
183183
<p className="mt-2">
184-
<strong>Email:</strong> vermarohanfinal@gmail.com
184+
<strong>Email:</strong> rohan@surfsense.com
185185
</p>
186186
</section>
187187
</div>

surfsense_web/app/(home)/terms/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default function TermsOfService() {
216216
<h2 className="text-2xl font-semibold mb-4">12. Contact Us</h2>
217217
<p>If you have any questions about these Terms, please contact us at:</p>
218218
<p className="mt-2">
219-
<strong>Email:</strong> vermarohanfinal@gmail.com
219+
<strong>Email:</strong> rohan@surfsense.com
220220
</p>
221221
</section>
222222
</div>

surfsense_web/app/dashboard/[search_space_id]/onboard/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ const OnboardPage = () => {
122122
{/* Header */}
123123
<div className="text-center mb-8">
124124
<div className="flex items-center justify-center mb-4">
125-
<Logo className="w-12 h-12 mr-3" />
125+
<Logo className="w-12 h-12 mr-3 rounded-full" />
126126
<h1 className="text-3xl font-bold">Welcome to SurfSense</h1>
127127
</div>
128128
<p className="text-muted-foreground text-lg">
129-
Let's configure your SurfSense to get started
129+
Let's configure your LLM configurations to get started
130130
</p>
131131
</div>
132132

0 commit comments

Comments
 (0)