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

Implement and utilize countdown widget (for temporary deployments) #198

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

edan-bainglass
Copy link
Member

@edan-bainglass edan-bainglass commented Mar 4, 2025

This PR implement a count down widget for use in temporary deployments. The widget is added to the main notebook within a check for a demo-server-config.yml file.

To test, add ~/.aiidalab/demo-server-config.yml with duration: "##:##:##" in it. Try different times. In particular, try near 5 minutes to check the color change, and near 0 to see the final message.

Checking elapsed time is done via ps -o etime= -p 1, as suggested by @yakutovicha


image

image

image

@edan-bainglass
Copy link
Member Author

@superstar54 @mikibonacci can I get a review please? 🙏 Pinging @danielhollas also if he has time 🙂

Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @edan-bainglass , I missed the previous review request since I get flooded with hundreds of GitHub (action) emails daily. 🤣 .

See my comments below.

"\n",
"# For temporary deployments (e.g. demo server), duration is read from a local\n",
"# config file. This will initiate the countdown widget.\n",
"demo_server_config_file = Path.home() / \".aiidalab\" / \"demo-server-config.yml\"\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the QEapp, we don't want to hardcode the demo-server in the app, so I would suggest using aiidalab-home.yaml, or aiidalab.yaml directly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is explicitly for demo servers (not our demo server, but for demo servers)

start.ipynb Outdated
"demo_server_config_file = Path.home() / \".aiidalab\" / \"demo-server-config.yml\"\n",
"if demo_server_config_file.exists():\n",
" demo_server_config = safe_load(demo_server_config_file.read_text())\n",
" countdown = CountDownWidget(duration=demo_server_config.get(\"duration\", \"12:00:00\"))\n",
Copy link
Member

@superstar54 superstar54 Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • change duration to a better name, e.g., container_lifetime
  • if the lifetime does not set explicitly in the config file, the default value should be a very long time (e.g., 10 years), instead of 12:00:00.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if the duration is not set in the config file, there should be no countdown widget deployed. I will adjust the conditional.

Comment on lines +234 to +236
if len(elapsed_str) < 6:
elapsed_str = f"00:{elapsed_str}"
elapsed_time = datetime.strptime(elapsed_str, "%H:%M:%S")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider time longer than one day, (maybe even months).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What use case are you thinking of here? I'm not trying to make this general. This is specifically for demo server deployments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that our current demo server only supports 12 hours, but since this is in the AiiDAlab-home, it should be more general, because other people may use this feature, or, we may use this feature in another deployment longer than 12 hours.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update this for "other people" down the road. For now, this is fine for our use case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just more caution for the aiidalab-home because every time we make a new release, the docker image must be upgraded.

But OK to me if you intend to leave this for the future.

@danielhollas
Copy link
Contributor

@edan-bainglass can you provide screenshots of how this looks? Is the countdown displayed only in the home page?

@edan-bainglass
Copy link
Member Author

@edan-bainglass can you provide screenshots of how this looks? Is the countdown displayed only in the home page?

Updated description with images. And yes, only on the home page.

@edan-bainglass
Copy link
Member Author

@edan-bainglass can you provide screenshots of how this looks? Is the countdown displayed only in the home page?

Updated description with images. And yes, only on the home page.

Hi @danielhollas. Did you have a question or comment regarding this PR?

@danielhollas
Copy link
Contributor

@edan-bainglass appologies for late answer, I've been moving to a new flat today so last week has been busy. :-)

What use case are you thinking of here? I'm not trying to make this general. This is specifically for demo server deployments.

My main concern here is that this doesn't feel like something that should live in aiidalab-home, at least not in its current form, as it is very specific to the upcoming demo server. I think it would be much better if this could somehow be part of QeApp image, which would allow you to iterate quickly regardless of aiidalab-home and full-stack image.

For example, you could have this as part of the QeApp's start.py.

@edan-bainglass
Copy link
Member Author

@edan-bainglass appologies for late answer, I've been moving to a new flat today so last week has been busy. :-)

What use case are you thinking of here? I'm not trying to make this general. This is specifically for demo server deployments.

My main concern here is that this doesn't feel like something that should live in aiidalab-home, at least not in its current form, as it is very specific to the upcoming demo server. I think it would be much better if this could somehow be part of QeApp image, which would allow you to iterate quickly regardless of aiidalab-home and full-stack image.

For example, you could have this as part of the QeApp's start.py.

This would limit the countdown to the QE App home app container. If for some reason the demo server user uninstalls the QE App (unlikely), no more countdown.

I understand that the countdown widget needs work to make it available for more use cases. However, I fail to see how this is an issue at the present stage. There have not been any use cases other than the demo server, so no hypothetical use cases will miss the fact that it is not yet general. Placing it here will immediately make it useful to its first use case. When time permits, we iterate, generalize, and release a patch or minor release. Please explain the practical reasons why you believe this shouldn't be accepted. I'm happy to change my opinion if I'm overlooking something.

@edan-bainglass
Copy link
Member Author

edan-bainglass commented Mar 11, 2025

I understand that the countdown widget needs work to make it available for more use cases. However, I fail to see how this is an issue at the present stage. There have not been any use cases other than the demo server, so no hypothetical use cases will miss the fact that it is not yet general. Placing it here will immediately make it useful to its first use case. When time permits, we iterate, generalize, and release a patch or minor release. Please explain the practical reasons why you believe this shouldn't be accepted. I'm happy to change my opinion if I'm overlooking something.

While you're at it, good if you can bullet point the missing features required in your opinion for this to be accepted here. I can then better assess if it is doable in a reasonable time frame 🙂

@danielhollas
Copy link
Contributor

However, I fail to see how this is an issue at the present stage.
Please explain the practical reasons why you believe this shouldn't be accepted. I'm happy to change my opinion if I'm overlooking something.

The issue is that if you put this here, that whenever you need to change it, you need to:

  1. Release aiidalab-home
  2. Release new full-stack image
  3. Release new QeApp image.

That's a lot of churn for something that you currently need only for the demo server. Also any code that's only for Demo server always risks breaking something for the other use cases (I am not saying this is the case here, just as a general principle).

If you don't want to tie it to QeApp, you could also just inject it as its own little app, i.e. put it inside a folder in /home/jovyan/apps and providing the start.py file, then aiidalab-home should pick it up automatically. (yes, sure, the user can uninstall it, but I fail to see that this is a valid concern).

In any case, I just wanted to raise this concern, I don't want to block anything. But that is another point, if the demo server stuff is localized to QeApp, then the review also doesn't need to be so strict since you can iterate faster. 🤷 :-)

@danielhollas
Copy link
Contributor

While you're at it, good if you can bullet point the missing features required in your opinion for this to be accepted here. I can then better assess if it is doable in a reasonable time frame 🙂

I think the main thing is that I would put this in the top header (perhaps next to the AiiDAlab app logo) since then it would be always displayed. If the user open QeApp, then it's going to be very easy to miss the countdown.

I also think that the timer should be implemented on the JS side, the only thing that it needs from the backend is the start time, right?

Right now you're executing subprocess call every second in a background thread, and change the HTML output every second, if I understand correctly. That's a lot of unnecessary traffic. More importantly, this can lead to a severe memory leak if the user closes the browser window unexpectedly (such putting his computer to sleep). We've had huge issues with this in the past, see:

https://github.com/aiidalab/issues/issues/13#issuecomment-1523233470

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregarding the philosophical issues discussed above, I am afraid this has a fundamental flaw of running infinite background thread that can cause memory leaks. Please have a look at https://github.com/aiidalab/issues/issues/13, I am happy to explain more.

)

def start(self):
Timer(1, self._update_countdown).start()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Infinitely running background threads that update the UI state are unfortunately a really bad idea due to a possible memory leak described in https://github.com/aiidalab/issues/issues/13.

I am afraid timer like this needs to be in javascript. If I am not mistaken, as long as the timer is initialized properly, it shouldn't need any information from the backend, right?

@edan-bainglass
Copy link
Member Author

Thank you @danielhollas. This is very clear. I will rethink my solution.

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

Successfully merging this pull request may close these issues.

3 participants