4.66.0
Some checks failed
Build-Release-Image / Build-Image (linux/arm64) (push) Failing after 7m18s
Build-Release-Image / Build-Image (linux/amd64) (push) Has been cancelled
Build-Release-Image / Merge-Images (push) Has been cancelled
Build-Release-Image / Create-Release (push) Has been cancelled
Build-Release-Image / Notify (push) Has been cancelled
Some checks failed
Build-Release-Image / Build-Image (linux/arm64) (push) Failing after 7m18s
Build-Release-Image / Build-Image (linux/amd64) (push) Has been cancelled
Build-Release-Image / Merge-Images (push) Has been cancelled
Build-Release-Image / Create-Release (push) Has been cancelled
Build-Release-Image / Notify (push) Has been cancelled
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from sqlalchemy_utils.types.arrow import arrow
|
||||
|
||||
from app.config import JOB_DELETE_MAILBOX
|
||||
from app.constants import JobType
|
||||
from app.db import Session
|
||||
from app.mail_sender import mail_sender
|
||||
from app.models import Alias, Mailbox, Job, AliasMailbox
|
||||
@ -21,7 +21,7 @@ def test_delete_mailbox_transfer_mailbox_primary(flask_client):
|
||||
alias_id = Alias.create_new(user, "prefix", mailbox_id=m1.id).id
|
||||
AliasMailbox.create(alias_id=alias_id, mailbox_id=m2.id)
|
||||
job = Job.create(
|
||||
name=JOB_DELETE_MAILBOX,
|
||||
name=JobType.DELETE_MAILBOX.value,
|
||||
payload={"mailbox_id": m1.id, "transfer_mailbox_id": m2.id},
|
||||
run_at=arrow.now(),
|
||||
commit=True,
|
||||
@ -43,7 +43,7 @@ def test_delete_mailbox_no_email(flask_client):
|
||||
user_id=user.id, email=random_email(), verified=True, flush=True
|
||||
)
|
||||
job = Job.create(
|
||||
name=JOB_DELETE_MAILBOX,
|
||||
name=JobType.DELETE_MAILBOX.value,
|
||||
payload={"mailbox_id": m1.id, "transfer_mailbox_id": None, "send_mail": False},
|
||||
run_at=arrow.now(),
|
||||
commit=True,
|
||||
@ -70,7 +70,7 @@ def test_delete_mailbox_transfer_mailbox_in_list(flask_client):
|
||||
alias_id = Alias.create_new(user, "prefix", mailbox_id=m1.id).id
|
||||
AliasMailbox.create(alias_id=alias_id, mailbox_id=m2.id)
|
||||
job = Job.create(
|
||||
name=JOB_DELETE_MAILBOX,
|
||||
name=JobType.DELETE_MAILBOX.value,
|
||||
payload={"mailbox_id": m2.id, "transfer_mailbox_id": m3.id},
|
||||
run_at=arrow.now(),
|
||||
commit=True,
|
||||
@ -95,7 +95,7 @@ def test_delete_mailbox_no_transfer(flask_client):
|
||||
|
||||
alias_id = Alias.create_new(user, "prefix", mailbox_id=m1.id).id
|
||||
job = Job.create(
|
||||
name=JOB_DELETE_MAILBOX,
|
||||
name=JobType.DELETE_MAILBOX.value,
|
||||
payload={"mailbox_id": m1.id},
|
||||
run_at=arrow.now(),
|
||||
commit=True,
|
||||
|
@ -1,7 +1,7 @@
|
||||
from app import config
|
||||
from app.db import Session
|
||||
from job_runner import get_jobs_to_run
|
||||
from app.models import Job, JobState
|
||||
from app.models import Job, JobPriority, JobState
|
||||
import arrow
|
||||
|
||||
|
||||
@ -56,18 +56,65 @@ def test_get_jobs_to_run(flask_client):
|
||||
run_at=now.shift(hours=3),
|
||||
)
|
||||
# Job out of attempts
|
||||
(
|
||||
Job.create(
|
||||
name="",
|
||||
payload="",
|
||||
state=JobState.taken.value,
|
||||
taken_at=now.shift(minutes=-(config.JOB_TAKEN_RETRY_WAIT_MINS + 10)),
|
||||
attempts=config.JOB_MAX_ATTEMPTS + 1,
|
||||
),
|
||||
Job.create(
|
||||
name="",
|
||||
payload="",
|
||||
state=JobState.taken.value,
|
||||
taken_at=now.shift(minutes=-(config.JOB_TAKEN_RETRY_WAIT_MINS + 10)),
|
||||
attempts=config.JOB_MAX_ATTEMPTS + 1,
|
||||
)
|
||||
# Job marked as error
|
||||
Job.create(
|
||||
name="",
|
||||
payload="",
|
||||
state=JobState.error.value,
|
||||
taken_at=now.shift(minutes=-(config.JOB_TAKEN_RETRY_WAIT_MINS + 10)),
|
||||
attempts=config.JOB_MAX_ATTEMPTS + 1,
|
||||
)
|
||||
|
||||
Session.commit()
|
||||
jobs = get_jobs_to_run()
|
||||
taken_before_time = arrow.now().shift(minutes=-config.JOB_TAKEN_RETRY_WAIT_MINS)
|
||||
jobs = get_jobs_to_run(taken_before_time)
|
||||
assert len(jobs) == len(expected_jobs_to_run)
|
||||
job_ids = [job.id for job in jobs]
|
||||
for job in expected_jobs_to_run:
|
||||
assert job.id in job_ids
|
||||
|
||||
|
||||
def test_get_jobs_to_run_respects_priority(flask_client):
|
||||
now = arrow.now()
|
||||
for job in Job.all():
|
||||
Job.delete(job.id)
|
||||
|
||||
j1 = Job.create(
|
||||
name="", payload="", run_at=now.shift(minutes=-1), priority=JobPriority.High
|
||||
)
|
||||
j2 = Job.create(
|
||||
name="", payload="", run_at=now.shift(minutes=-2), priority=JobPriority.Default
|
||||
)
|
||||
j3 = Job.create(
|
||||
name="", payload="", run_at=now.shift(minutes=-3), priority=JobPriority.Default
|
||||
)
|
||||
j4 = Job.create(
|
||||
name="", payload="", run_at=now.shift(minutes=-4), priority=JobPriority.Low
|
||||
)
|
||||
j5 = Job.create(
|
||||
name="", payload="", run_at=now.shift(minutes=-2), priority=JobPriority.High
|
||||
)
|
||||
|
||||
Session.commit()
|
||||
taken_before_time = arrow.now().shift(minutes=-config.JOB_TAKEN_RETRY_WAIT_MINS)
|
||||
jobs = get_jobs_to_run(taken_before_time)
|
||||
assert len(jobs) == 5
|
||||
|
||||
job_ids = [job.id for job in jobs]
|
||||
|
||||
# The expected outcome is:
|
||||
# 1. j5 -> 2 mins ago and High
|
||||
# 2. j1 -> 1 min ago and High
|
||||
# --- The 2 above are high, so they should be the first ones. j5 is first as it's been pending for a longer time
|
||||
# 3. j3 -> 3 mins ago and Default
|
||||
# 4. j2 -> 2 mins ago and Default
|
||||
# --- The 2 above are both default, and again, are sorted by run_at ascendingly
|
||||
# 5. j4 -> 3 mins ago and Low. Even if it is the one that has been waiting the most, as it's Low, it's the last one
|
||||
assert job_ids == [j5.id, j1.id, j3.id, j2.id, j4.id]
|
||||
|
@ -1,6 +1,6 @@
|
||||
import arrow
|
||||
|
||||
from app import config
|
||||
from app.constants import JobType
|
||||
from app.events.generated.event_pb2 import EventContent, AliasDeleted
|
||||
from app.jobs.send_event_job import SendEventToWebhookJob
|
||||
from app.models import PartnerUser
|
||||
@ -17,7 +17,7 @@ def test_serialize_and_deserialize_job():
|
||||
run_at = arrow.now().shift(hours=10)
|
||||
db_job = SendEventToWebhookJob(user, event).store_job_in_db(run_at=run_at)
|
||||
assert db_job.run_at == run_at
|
||||
assert db_job.name == config.JOB_SEND_EVENT_TO_WEBHOOK
|
||||
assert db_job.name == JobType.SEND_EVENT_TO_WEBHOOK.value
|
||||
job = SendEventToWebhookJob.create_from_job(db_job)
|
||||
assert job._user.id == user.id
|
||||
assert job._event.alias_deleted.id == alias_id
|
||||
|
Reference in New Issue
Block a user