Ep.4 Scheduler | Supbot Whatsapp Chatbot API

in #utopian-io6 years ago

small banner.jpg

Repository

https://github.com/adsau59/supbot

What Will I Learn?

  • What is Scheduler used for in Supbot API?
  • How Scheduler works in Supbot API?
  • How to use Scheduler in Supbot API?

Requirements

Required Knowledge

Resources for this Tutorial:

Difficulty

Basic
✔Intermediate
Advanced

Description

Outline and Overview

In this Supbot tutorial we will take a look on Scheduler.

What is Scheduler used for?

It is used in two ways,

  • Periodic Task,
    Tasks which are performed on an interval, like daily, weekly, yearly tasks
  • Timed Task,
    Tasks which are scheduled for a specific time, like reminders
How does Scheduler works?

Scheduler in Supbot API works using 3 componnets,

  • SchdeuleTask
  • Schedule
  • ScheduleManager
ScheduleTask

scheduletask.PNG

ScheduleTask is an interface with 3 methods,

  • task(): This method is used is executed when the schedule is arrived.
  • taskMissed(): This method is used is executed when the schedule is missed.
  • getNextSchedule(): This method is used to reschedule the date for the next schedule, can return null if the schedule is to be destroyed after running.
  • ScheduleTask implements Serializable.
Schedule

schedule_constructor.PNG

  • Schedule class encapsulates ScheduleTask, the date for schedule and the timer object.
  • Schedule also calculates the delay for the Schedule when the bot is launched.
ScheduleManager

schedule_manager_add.PNG

ScheduleManager has two jobs,

  • First is to add the schedule to the database when it is added,
  • and Second is to reload the schedule back when the bot is started.
How to use Scheduler?

There are two methods to use Scheduler,

  • Static Method
  • Dynamic Method
Static Method

schedule_cc.PNG

Static Method of creating Scheduler is used when you want to create the schedule yourself and has to be initialized just once.
In order to create Scheduler using static method you have to,

  • Create a class which implements ScheduleTask.
  • Add the class object of the class you made into ScheduleTaskInitializer using Bot.getScheduleTaskInitializer.add() method in the addThingsInBot method in the Main class.
  • then use schedule create console command to initialize the Schedule.
Dynamic Method

schedule_manager_add_use.PNG

Dynamic Method of creating Scheduler is used when you want the clients to create the schedule or it has to be initialized multiple times.
In order to create Scheduler using dynamic method you have to,

  • Create a class which implements ScheduleTask.
  • Create a Schedule Object using it.
  • Add it into ScheduleManager using Bot.getScheduleManager.add() method.

After we learn about Scheduler, we will look both of these methods in the video tutorial by creating,

  • GoodMorning Scheduler, which sends good morning messege every morning, and
  • RemindMe Command, which creates a reminder for the time the client specifies using natty API

Creating the GoodMorning Scheduler you will learn how to create Schedule using Static method and creating RemindMe Command you will learn how to create Schedule using Dynamic method.

This will create an understanding for you by which you can use both of these methods when it is required when you create your own features.

Video Tutorial

Curriculum

Contact

If you have any problems or you want to contact me on DefineX Community discord server

Proof of Work Done

https://github.com/adsau59

Sort:  

Hello @adam-saudagar,

Thank you for your contribution to the video tutorial category.

  • I see that you are improving in your tutorial presentation.
  • The lessons are more structured.
  • You are explaining the concepts more as you move along in the different steps.
  • There is an echo sound in the audio. Try to close all the windows and put some blankets around the windows.
  • You need to work on the speech delivery.
  • You need to speak slower so that your words can be heard clearly. Right now, they are jumbled up. Try to pause before you move on to the next sentence.

In this tutorial, the word 'schedule' is used a lot. You mispronounced the word and this can be very annoying to the listener. So what you need to do is to look up the words that occur frequently and make sure you know how to pronounce the words. This will help to improve your audio presentation greatly.

I look forward to your next presentation.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for the review,

Sorry for the echo, just bought a new microphone to create vids, will try to configure it better

and for the "schedule",
In India, we use UK English pronunciation. Check this out

Thank you for your review, @rosatravels! Keep up the good work!

Hi @adam-saudagar!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @adam-saudagar!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @adam-saudagar! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 250 as payout for your posts. Your next target is to reach a total payout of 500

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

The new Steemfest³ Award is ready!
Be ready for the next contest!

Support SteemitBoard's project! Vote for its witness and get one more award!