Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a job is forcibly cancelled by calling stop(), the added schedule to the scheduler will no longer create new job. #903

Open
3 tasks done
Trung0246 opened this issue May 5, 2024 · 1 comment
Labels

Comments

@Trung0246
Copy link

Trung0246 commented May 5, 2024

Things to check first

  • I have checked that my issue does not already have a solution in the FAQ

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Version

4.0.0a4

What happened?

How the schedule was created:

	
TRACK_ENGINE = sqlalchemy.ext.asyncio.create_async_engine(f"sqlite+aiosqlite:///{schedule_path}")
pathlib.Path(schedule_path).parent.mkdir(parents=True, exist_ok=True)
TRACK_DB = apscheduler.datastores.sqlalchemy.SQLAlchemyDataStore(
	engine=TRACK_ENGINE,
)

async with apscheduler.AsyncScheduler(data_store=TRACK_DB) as scheduler:
	TRACK_SCHEDULE = scheduler

await TRACK_SCHEDULE.add_schedule(
	track_handle,
	apscheduler.triggers.interval.IntervalTrigger(
		weeks=data.get("weeks", 0),
		days=data.get("days", 0),
		hours=data.get("hours", 0),
		minutes=data.get("minutes", 0),
		seconds=data.get("seconds", 0),
		microseconds=data.get("microseconds", 0),
		start_time=data.get("start_time", datetime.datetime.now()),
		end_time=data.get("end_time", None),
	),
	max_running_jobs = 1,
	conflict_policy = apscheduler.ConflictPolicy.do_nothing
)

The schedule termination mechanism:

await asyncio.gather(TRACK_SCHEDULE.stop(), TRACK_SCHEDULE.wait_until_stopped())

How can we reproduce the bug?

This only happens when the job is RUNNING, not when it's finished and therefore we can safely cancel during that time span.

Use the above code to plug in appropriate order. When TRACK_SCHEDULE restarted with new python runtime instance, the job no longer getting created.

The problem is probably this:

image

Looks like running_jobs is still at 1 despite the job being cancelled.

@Trung0246 Trung0246 added the bug label May 5, 2024
@agronholm
Copy link
Owner

Can you reproduce this on master? I've made TONS of changes around this area, and the problem may not exist anymore. If it does, would you mind creating a minimal working example for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants