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

Why work only with tty: true? #31

Open
Foldren opened this issue Oct 2, 2024 · 10 comments
Open

Why work only with tty: true? #31

Foldren opened this issue Oct 2, 2024 · 10 comments
Labels
invalid Seems to not be a valid issue unreproducible Unreproducible

Comments

@Foldren
Copy link

Foldren commented Oct 2, 2024

I tried to start the application aioclock in the docker container but it doesn't start without tty: true

@ManiMozaffar
Copy link
Owner

Can you share the logs of container when you run without tty?
I’m using the library without using tty. It’s working fine, I guess the issue is somewhere else

@ManiMozaffar
Copy link
Owner

@Foldren
I think I understand why
So aioclock serve function basically exit if there’s no more task to be running, why keep running a forever idle application?

for that to happen, all your trigger conditions should no longer ever satisfy. For example having loop_count=1 ensures all tasks are executed only once. If all tasks are executed, then aioclock quit as mentioned.

There is 2 possible scenarios:

  1. Either it correctly determines that no longer task happened
  2. Or it incorrectly determined that and you actually had some tasks to be running.

i can improve logging a bit to make this more clear,
But if you share your triggers that you use, that would reproduce what happened and we can find out it was a bug or not.

@Foldren
Copy link
Author

Foldren commented Oct 10, 2024

On start in lifespan i get message, but it's doesn't work without tty

@ManiMozaffar
Copy link
Owner

Can you provide a snippet code that reproduce the issue? @Foldren
I'm 99% sure the root of cause is aioclock quitting for some reasons. that's why tty true would fix it.

@Foldren
Copy link
Author

Foldren commented Oct 11, 2024

from asyncio import run
from contextlib import asynccontextmanager
from aioclock import AioClock, At, Every, Once
from tortoise import Tortoise
from config import TORTOISE_CONFIG, APP_NAME
from modules.logger import Logger
from modules.playwright.maybank import Maybank


@asynccontextmanager
async def lifespan(_: AioClock):
    await Tortoise.init(TORTOISE_CONFIG)
    await Tortoise.generate_schemas(safe=True)
    await Logger(APP_NAME).success(msg="Started.", func_name="startup")
    yield _

app = AioClock(lifespan=lifespan)


@app.task(trigger=At(tz="Europe/Moscow", hour=3, minute=5))
async def load_stats():
    await Maybank().load_stats()


if __name__ == '__main__':
    run(app.serve())

@Foldren
Copy link
Author

Foldren commented Oct 11, 2024

by the way, it would be cool to add your own logger to aioclock

@ManiMozaffar
Copy link
Owner

ManiMozaffar commented Oct 15, 2024

@Foldren I don't understand what do you mean by own logger, we're using python stdlib logger which is highly configurable and should be compatible with any other logging libraries.
If you raise Exception in your lifespan, it would raise th exception all the way up. I can also document this, doesn't matter also it should be case with Start and End event as well.
I think the setup you do with tortoise sometimes fail and raise exception, can you put a try catch to see if there's any exception on your side? This should likely to solve your problem.

P.S: you can run this code few time to understand what I mean :)

import asyncio
import random
from contextlib import asynccontextmanager

from aioclock import AioClock, Once


@asynccontextmanager
async def lifespan(app: AioClock):
    print("Hey")
    if random.choice([True, False]):
        raise Exception("lifespan")
    yield app
    print("Bye")


app = AioClock(lifespan=lifespan)


@app.task(trigger=Once())
async def foo():
    print("foo")


if __name__ == "__main__":
    asyncio.run(app.serve())

@ManiMozaffar ManiMozaffar added unreproducible Unreproducible invalid Seems to not be a valid issue labels Oct 16, 2024
@ManiMozaffar
Copy link
Owner

Closing due to inactivity.

@Foldren
Copy link
Author

Foldren commented Dec 2, 2024

Can you try launch this in docker and send container log?

@Foldren
Copy link
Author

Foldren commented Dec 5, 2024

Well, the problem has not been solved

@ManiMozaffar ManiMozaffar reopened this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Seems to not be a valid issue unreproducible Unreproducible
Projects
None yet
Development

No branches or pull requests

2 participants