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

[PR] Add "resuming" handlers for resources (as co-handlers) #105

Closed
2 tasks
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Closed
2 tasks

[PR] Add "resuming" handlers for resources (as co-handlers) #105

kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Labels
archive enhancement New feature or request

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

A pull request by nolar at 2019-06-06 18:47:27+00:00
Original URL: zalando-incubator/kopf#105
Merged by nolar at 2019-06-14 09:04:11+00:00

Issue : closes #60, replaces #96

Description

Add the handlers for "resuming" (recalling? remembering?) an object in the operator:

@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
def on_resume(**kwargs): pass

This complements the existing handlers for creation/update/deletion cases, and is injected into the handling cycle when one of the mentioned cases is detected (and handled normally), but strictly when the operator has started/restarted, and found that the object existed beforehand.

Which implies that if the object was created during the operator downtime, both @kopf.on.create AND @kopf.on.resume handlers will be called. Similarly, of the object was changed during the operator downtime, both @kopf.on.update AND @kopf.on.resume will be called (and both will get a diff of the object).


BUT: See #103 for the de-duplication of the same function if it is registered for few causes.

This "double-cause" patten becomes possible to start a background job for permanent object monitoring (the function will be called only once when the object appears: either while the operator is running and it is created, or when the operator starts and a new unhandled object is found, or when the operator starts and an existing handled object is found):

@kopf.on.create('zalando.org', 'v1', 'kopfexamples')
@kopf.on.resume('zalando.org', 'v1', 'kopfexamples')
async def start_monotoring(**kwargs): pass
    loop = asyncio.get_running_loop()
    loop.create_task(a_long_running_coroutine(**kwargs))

    thread = threading.Thread(target=a_long_running_function, kwargs=kwargs)
    thread.start()

Difference from #96: Unlike a solution in #96, where the resuming handler is triggered when the object is neither created, nor updated, nor deleted, but noticed to exist, in this PR, the resume handler is called event if update/creation/deletion detected, as part of the relevant handling cycle (i.e. as one of the handlers on the list).


As a side-note: I could not decide between "resume" and "recall" for proper naming. It is "resume", as it resumes some thread that was previously running in a now-dead operator. It is "recall", as it kind of "recalls" (remembers) the object: "ah, there is also such a thing with uid 123, which is not changed!". The naming can be changed before merged.

Types of Changes

  • New feature (non-breaking change which adds functionality)
  • Refactor/improvements
  • Documentation / non-code

Review

  • Tests
  • Documentation

Commented by samurang87 at 2019-06-12 15:36:18+00:00
 

I prefer "resume" :)

@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] [PR] Add "resuming" handlers for resources (as co-handlers) Aug 19, 2020
@kopf-archiver kopf-archiver bot added the enhancement New feature or request label Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

0 participants