Coder Social home page Coder Social logo

Add a Celery support about tgflow HOT 7 CLOSED

sakost avatar sakost commented on June 16, 2024
Add a Celery support

from tgflow.

Comments (7)

danlkv avatar danlkv commented on June 16, 2024

Sounds really awesome! I'll do it (someday)

from tgflow.

danlkv avatar danlkv commented on June 16, 2024

Hi, it seems that there's no need for this, you can now use ordinary time.sleep()function and tgf.send_state() to send a delayed notification. Check out an example: https://github.com/DaniloZZZ/tgflow/blob/master/examples/delayed.py

from tgflow.

sakost avatar sakost commented on June 16, 2024

It's not what I meant
My example implies that you can change states before the task started
It is a notification feature, so it may be more correct not to allow to change the current state
My fixed example:

def func(i, s, **d):
    @tgflow.task(change_state=False)  # if True then function must contain a return statement
    def celery_task(i, s, **d):  # some arguments
        # doing something
        return # "return States.SUCCESS, d" if "change_state" is True
    task = celery_task()
    tgflow.schedule(task, 30*60)  # 30 minutes
    return States.NEXT_STATE, d

from tgflow.

danlkv avatar danlkv commented on June 16, 2024

If you don't want to change state on notification, you can send a raw message:

A modified code from example will be:

def handle_delay(i, s, **d):
    delay = int(i.text)
    tgf.send_state(States.SET, i.from_user.id, data = {'delay':delay})
    print("sleeping for",delay)
    time.sleep(delay)
    tgf.send_raw("Notification!", i.user.id)
    print("done",delay)
    return States.MENU, {'notification_sent':true}

from tgflow.

sakost avatar sakost commented on June 16, 2024

If you don't want to change state on notification, you can send a raw message:

A modified code from example will be:

def handle_delay(i, s, **d):
    delay = int(i.text)
    tgf.send_state(States.SET, i.from_user.id, data = {'delay':delay})
    print("sleeping for",delay)
    time.sleep(delay)
    tgf.send_raw("Notification!", i.user.id)
    print("done",delay)
    return States.MENU, {'notification_sent':true}

But it will be block the thread, isn't it? and so you will not receive updates from server at that moment

from tgflow.

danlkv avatar danlkv commented on June 16, 2024

No, it seems that telebot is handling a connection in a separate thread. I haven't tested for other platforms, though, but telegram works ok.

from tgflow.

sakost avatar sakost commented on June 16, 2024

okey. then I close the issue.

from tgflow.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.