Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions workflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection, models
from django.db import models
from django.utils.timezone import now
from django.utils.translation import gettext_lazy
from django.utils.translation import gettext_lazy as _
from django_celery_beat.models import CrontabSchedule, PeriodicTask

from workflow.storage import get_storage
from workflow.utils import get_all_tenant_schemas, get_next_node_by_condition
from workflow.utils import get_next_node_by_condition
from workflow_app import celery_app

LANGUAGE_MAX_LENGTH = 5
Expand Down Expand Up @@ -594,16 +594,7 @@ def handle_task_success(self, retval):

class ScheduleManager(models.Manager):
def enabled(self):
result = []
schemas = get_all_tenant_schemas()

for schema in schemas:
with connection.cursor() as cursor:
cursor.execute(f"SET search_path TO {schema};")

schema_schedules = list(self.filter(enabled=True).prefetch_related("crontab"))
result.extend(schema_schedules)
return result
return self.filter(enabled=True).prefetch_related("crontab")


class Schedule(PeriodicTask, TimeStampedModel):
Expand Down
2 changes: 1 addition & 1 deletion workflow/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def all_as_schedule(self):
set_schema_from_context({"space_code": schema})
for model in self.Model.objects.enabled():
try: # noqa: SIM105
s[model.name] = self.Entry(model, app=self.app)
s[f"{schema}:{model.name}"] = self.Entry(model, app=self.app)
except ValueError:
pass
return s
Expand Down
4 changes: 1 addition & 3 deletions workflow/tasks/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ def execute(self, user_code, payload, is_manager, *args, **kwargs):

logger.info("periodic.schedule_id %s", schedule_id)

Schedule.objects.filter(id=schedule_id).update(last_run_at=now())
schedule = Schedule.objects.get(id=schedule_id)

schedule.last_run_at = now()
schedule.save()

owner = User.objects.get(username=schedule.owner.username)
space = Space.objects.get(space_code=context.get("space_code"))

Expand Down