Add new operation Scheduled Job to Operation enum of ProcessLock

This commit is contained in:
Debanjum Singh Solanky 2024-04-17 12:23:55 +05:30
parent c28d7d3414
commit fcf878e1f3
3 changed files with 22 additions and 2 deletions

View file

@ -324,7 +324,7 @@ def update_content_index():
@schedule.repeat(schedule.every(22).to(25).hours) @schedule.repeat(schedule.every(22).to(25).hours)
def update_content_index_regularly(): def update_content_index_regularly():
ProcessLockAdapters.run_with_lock( ProcessLockAdapters.run_with_lock(
update_content_index, ProcessLock.Operation.UPDATE_EMBEDDINGS, max_duration_in_seconds=60 * 60 * 2 update_content_index, ProcessLock.Operation.INDEX_CONTENT, max_duration_in_seconds=60 * 60 * 2
) )

View file

@ -0,0 +1,19 @@
# Generated by Django 4.2.10 on 2024-04-16 18:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("database", "0035_processlock"),
]
operations = [
migrations.AlterField(
model_name="processlock",
name="name",
field=models.CharField(
choices=[("index_content", "Index Content"), ("scheduled_job", "Scheduled Job")], max_length=200
),
),
]

View file

@ -109,7 +109,8 @@ class Agent(BaseModel):
class ProcessLock(BaseModel): class ProcessLock(BaseModel):
class Operation(models.TextChoices): class Operation(models.TextChoices):
UPDATE_EMBEDDINGS = "update_embeddings" INDEX_CONTENT = "index_content"
SCHEDULED_JOB = "scheduled_job"
# We need to make sure that some operations are thread-safe. To do so, add locks for potentially shared operations. # We need to make sure that some operations are thread-safe. To do so, add locks for potentially shared operations.
# For example, we need to make sure that only one process is updating the embeddings at a time. # For example, we need to make sure that only one process is updating the embeddings at a time.