1. Домой
  2. Документы
  3. Smarty (English version)
  4. Smarty configuring and management
  5. Service and regular commands

Service and regular commands

Service commands are called using the smarty_manage script and are intended to perform certain regular and system tasks, such as updating EPG or deleting outdated data. Some commands are required for the service to function properly.

Instead of <settings name> in the commands, specify your configuration file, which is located at /etc/microimpuls/smarty/.

General commands

Cache update

Command:

smarty_manage flushall —settings=settings.<settings name>

Smarty has two types of cache:

  • protected cache is data that is written to the cache for the sake of speed of access and is not cleared during updating: content viewing marks, video server keys, etc.
  • regular cache is temporarily saved data to speed up the system: saved API responses from the server.

By default, the flushall command clears only the regular cache.

Parameters:

—flush-protected — force flushing of the protected cache.

smarty_manage flushall —flush-protected —settings=settings.<settings name>

System performance testing

Command:

smarty_manage performance_test —settings=settings.<settings name>

A test is carried out depending on the selected testing purpose:
—redis – speed of writing, reading and deleting data.
—database – speed of creating and reading data.
—proc – execution time for sorting the data array.

After running the tests, the execution time of each test with the selected data size and the estimated number of requests/operations per second (rps) are displayed.

Parameters:
-s, —small – performance testing is performed with a small amount of data.
-m, —mid — performance testing is performed with a medium amount of data.
-b, —big — performance testing is performed with a large amount of data.
-r, —redis – if this flag is present, redis will be checked.
-db – if this flag is present, the database will be checked.
-p, —proc – if this flag is present, the processor performance will be checked.
-a, —all – full system scan flag (includes –r, -db, -p).

Examples of using the command:
CPU load test with large amount of data:

smarty_manage performance_test —proc —big —settings=settings.<settings name>

/usr/share/microimpuls/smarty-lite/manage.py performance_test —proc —big —settings=settings.smarty-lite

Processor test
Sorting values in test list…
time: 242.4418 22914546.2145 rps

Full system load test with medium amount of data:

smarty_manage performance_test -a —mid —settings=settings.<settings name>

/usr/share/microimpuls/smarty-lite/manage.py performance_test -a —mid —settings=settings.smarty-lite

Redis test
Setting value in redis…
time: 47.9694 10423.3085 rps
Receiving values from redis…
time: 46.3872 10778.8313 rps
Deleting values from redis…
time: 46.2279 10815.9741 rps

DB test
Creating value in db table…
time: 1.3785 362.7209 rps
Receiving values from db table…
time: 6.4660 7732.7368 rps

Processor test
Sorting values in test list…
time: 59.1231 23489591.2796 rps

Customers

Write-off/renewal of accounts using built-in billing according to billing periods

Command:

smarty_manage check_accounts —settings=settings.<settings name>

The command deactivates accounts for which the billing period has come to an end, and also writes off funds and renews existing accounts. It is recommended to run every night (see Description of the built-in billing).

Deleting all authorization sessions for all accounts for a given Client ID

Command:

smarty_manage delete_authkeys —client_id=<client_id> —settings=settings.<settings name>

Attention, executing this command will log out all devices.

Clearing a customer activity log

Command:

smarty_manage clear_customer_log —days=60 —settings=settings.<settings name>

Parameters:

—days — this parameter is required and determines that when calling the command, records older than “days” days will be deleted.

Payments

Auto payment command

Command:

smarty_manage make_autopayments —settings=settings.<settings name>

Makes payments for those clients who have auto payment active. It is recommended to execute directly before the check_accounts command.

Parameters:

—use_pool — enables multithreaded processing of customer auto payments.

Payment validation command

Command:

smarty_manage check_payment_status —settings=settings.<settings name>

Checks the payment status for payment systems that do not have automatic notification. Fortebank and Payture are currently supported.

Parameters:

—timeout_minutes — the number of minutes after which the payment is considered “outdated” and is no longer verified.

Sending messages

Sending information messages to device screens and e-mail about the approaching deactivation period/need for payment

Command:

smarty_manage send_activation_expires_messages —client_id=<client_id> —days_count=<number of days remaining> —settings=settings.<settings name>

Parameters:

—days_count — this parameter is mandatory and creates a selection of accounts whose period before deactivation is equal to the passed parameter.

—send_sms — when this parameter is specified, messages will also be sent via SMS if a customer has a phone number specified. It is recommended to run this command once a day.

Example of using the command:

Sending an SMS notification that the deadline for account deactivation is approaching for the Client with ID=25:

smarty_manage send_activation_expires_messages —client_id 25 —days_count 3 —send_sms —settings=settings.<settings name>

Deleting old undelivered information messages

Command:

smarty_manage clean_old_messages —days_count <amount of days> —hours <amount of hours> —minutes <amount of minutes> —settings=settings.<settings name>

Using this command, you can delete messages from a certain date that are no longer relevant. If you specify several parameters, the period is summed depending on the parameters passed.

Warning: if you do not specify —days_count when executing the command, the default value of the parameter is taken.

Parameters:

—days_count — responsible for deleting messages created X or more days ago. Default: 7.

—hours — responsible for deleting messages created X or more hours ago. Default: 0.

—minutes — responsible for deleting messages created X or more minutes ago. Default: 0.

Example of using the command:

Deleting messages that were created more than 3.5 hours ago:

smarty_manage clean_old_messages —days_count=0 —hours=3 —minutes=30 —settings=settings.<settings name>

Resending SMS messages that were not delivered the first time

Command:

smarty_manage resend_sms —settings=settings.<settings name>

It is recommended to run this command every 1-3 minutes.

Content

Caching the list of TV channels for customer devices

Command:

smarty_manage cache_channel_list —settings=settings.<settings name>

Parameters:

—content_type — used to separate caching of cameras and channels. Possible values: all, camera, channel. Default value: all.

It is recommended to run this command every minute. If the TV channel list cache is empty, a customer will receive a message that the TV channel list is empty.

Creating a selection of popular TV channels

Command:

smarty_manage create_channel_selection_by_popularity —settings=settings.<settings name>

Warning: the TV viewing statistics module must be configured for this command to work.

Parameters:
—client_id – this parameter is mandatory and defines the Client identifier for which a selection will be created.
—days_number – this parameter is mandatory and defines the number of days during which TV viewing should be taken into account.
—criterion – this parameter is mandatory and defines the characteristic by which a selection will be created. Possible values: watch_time (total channel viewing time), watch_sessions (number of channel viewing sessions), average_watch_time (average channel viewing time), median_watch_time (median viewing time).
—devices – parameter to create a selection for specific devices (by default, a selection is created for all devices).
—accounts_active – this parameter allows creating a selection only on the basis of active accounts. Possible values: true, false. Default is false.
—tariffs – this parameter selects specific tariffs to create a selection (by default all tariffs are taken into account).
—selection_size – this parameter defines the size of a created selection. If there is no information about the sufficient number of channels, channels without statistics are added up to the required number. Default: 17.

Example of using the command:

Creating for Client=1 a selection of weekly popular channels by viewing time:

smarty_manage create_channel_selection_by_popularity —client_id=1 —days_number=7 —criterion=watch_time —settings=settings.<settings name>

Creating a selection of popular TV programs

Command:

smarty_manage create_epg_selection_by_popularity —settings=settings.<settings name>

Warning: the TV viewing statistics module must be configured for this command to work.

Parameters:
—client_id – this parameter is mandatory and defines the Client identifier for which a selection will be created.
—days_number – this parameter is mandatory and defines the number of days during which information on TV programs is collected.
—devices – parameter to create a selection for specific devices (by default, a selection is created for all devices).
—tariffs – this parameter selects specific tariffs to create a selection (by default all tariffs are taken into account).
—selection_size – parameter defines the size of a created selection. If there is no information about the sufficient number of TV programs, TV programs without statistics are added up to the required number. Default: 17.
—categories – this parameter allows creating a selection by specific channel categories (by default all categories are taken into account), category id can be seen in Content Settings — TV Categories.
—channels – TV programs of only those channels whose ids are specified in this parameter are taken into account.
—selection_name – the name of a selection. If not specified, a selection will be named «Selection name $days_number ($selection_size)».

Example of using the command:

Creating a selection of 27 popular programs for Client=1 in 30 days with categories «Children’s» (id=2) and «Educational» (id=7):

smarty_manage create_epg_selection_by_popularity —selection_name=»Children’s educational» —client_id=1 —days_number=30 —selection_size=27 —categories=2 —categories=7 —settings=settings.<settings name>

Transferring movie watch marks to a permanent database

Command:

smarty_manage save_content_position —settings=settings.<settings name>

Remembering the position where the user stopped while watching a movie is done by sending the relevant position to Smarty from the application every 30 seconds. Saving this position every time in the database is quite a heavy operation, so by default it is saved to the protected cache. But since the cache, even protected, is still a temporary entity, and it is important to keep a user’s watch history for a long time — it is possible to transfer these watches to the main database using the save_content_position command. It is recommended to run it at least once a day.

Deleting movie watch history for all customers

Command:

smarty_manage remove_viewed_content_history —settings=settings.<settings name>

Parameters:

—client_id — the Client identifier for whose customers you want to clear the watch history.

 —days — watches older than this number of days should be cleared.

The command allows you to delete the watch history of users older than a certain number of days to avoid storing data that is, for example, one year old.

Caching a list of countries sorted by number of movies

Command:

smarty_manage cache_video_country_list —settings=settings.<settings name>

This command is needed to display a list of countries on the movie filter screen in the application interface. It is recommended to run once a day. If the cache is empty, the TVMW API will return an empty list of countries.

Generating feeds from archived records

Command:

smarty_manage cache_record_feed —client_id=<client_id> —settings=settings.<settings name>

The command collects and generates feeds from archive records. If the —client_id parameter is specified, generation will be done for a specific Client (otherwise generation will be done for all available Clients). The feeds are available at: smarty.example.com/tvmiddleware/record/feed/<client_id>.

EPG

Importing EpgChannel

Command:

smarty_manage epg_channel_import —settings=settings.<settings name>

The command loads the channel list or updates the icon list from an EPG source (EpgService or any source in xmltv format). The —epg_import_id or —epg_source_name parameters are required to run the command.

When importing images, copies of different sizes specified in the SMARTY_DEFAULT_ICON_SIZES option are created if possible.

To update icons of a specific channel, you can specify—epg_channel_id or —channel_id.

Parameters:

—epg_source_id — identifier of the EpgSource in Smarty for which you want to import channels.

—epg_source_name – the name of the EpgSource for which you want to import channels.

—epg_channel_id – identifier of EpgChannel for which you want to update the icon. It is located on the Django Smarty admin page.

—force_import – parameter is required to load all channels from a source list. When specified, all other parameters except —epg_source_id , —epg_source_name and —fix_duplicates are ignored.

—channel_id – identifier of the channel for which you want to update the icon. It is located on the Smarty admin page.

—reimport_icons – if this parameter is specified, imported channels will have their icons updated.

Example command for importing channels:

smarty_manage epg_channel_import —epg_source_id=2 —force_import —settings=settings.<settings name>

Importing EPG

Command:

smarty_manage epg_import —settings=settings.<settings name>

The command is required to load the list of TV programs. If the EPG is not imported, a customer will have an empty program guide and the service functionality will be limited.

Import can be performed either for all source channels by adding the —epg_source_id (—epg_source_name) parameter or for a specific channel by specifying —epg_channel_id. It is recommended to run the import several times a day to keep it up to date.

Parameters:

—epg_source_id – identifier of the EpgSource in Smarty for which you want to import the EPG.
—epg_source_name – the name of the EpgSource for which you want to import the EPG.
—epg_channel_id – identifier of the EpgChannel for which you want to import the EPG.
—actual_days – limit of the number of days in which programs are considered relevant. Programs older than the specified value are considered irrelevant and will be deleted if they exist.
—create_content – if this parameter is added, selections of imported programs will be created in parallel with import, it is necessary for the «Archive» section to work. If the —content_client_id parameter is absent, selections will be created for all Smarty clients.
—content_client_id – if this parameter is added, creation of selections will be performed only for a specific client. Used in conjunction with the —create_content parameter.
—ignore_epg_import – if this parameter is added, the command will not import the EPG. Used in conjunction with the —create_content parameter.
—start_date – the parameter accepts the date from which the list of program guides should be loaded. It is passed in the format YYYY-MM-DD. Using this parameter you can load an outdated EPG, for example, to fill the «Archive» section with past programs. Warning: the start_date parameter is prioritized over actual_days.
—force_reimport — intended for forced import of EPG, ignoring the date of the last update of the EPG source.

—force_parser_handling — forcibly allows the use of transferring control to the parser. During import, the date of the last change in the EPG source is checked (if there are changes, the import is performed). Necessary for the import optimization process. Equivalent to TVMW_EPG_IMPORT_ALLOW_PARSER_HANDLING=True.
—force_disable_parser_handling – forcibly disables the use of transferring control to the parser. If this parameter is added, the date of the last change in the EPG source is ignored. Equivalent to TVMW_EPG_IMPORT_ALLOW_PARSER_HANDLING=False.

Example of using the command:

Import the EPG from a specific date:

smarty_manage epg_import —epg_source_id=2 —start_date=2023-07-12

Delete outdated EPGs:

smarty_manage epg_import —epg_source_id=2 —actual_days=120

Import the EPG for a specific channel only:

smarty_manage epg_import —epg_source_id=2 —epg_channel_id=164 —start_date=2023-07-13

Importing EPG premieres

Command:

smarty_manage epg_premiere_import —settings=settings.<settings name>

Parameters:

—epg_channel_id – EpgChannel for which the EPG premieres will be imported.

It is recommended to run 1-2 times a day to keep the list of premieres up to date (see Setting up EPG and TV channel icons). If an import is not performed, the premiere list on a customer’s device will be empty.

Caching of existing icons

Command:

smarty_manage recache_icons —settings=settings.<settings name>

Called if there is no information about existing icons. The command checks and stores in the cache the existence of icons for all EpgChannels according to the sizes specified in SMARTY_DEFAULT_ICON_SIZE and SMARTY_DEFAULT_ICON_SIZES.

Broadcasting

Checking the availability of streaming services for the fault tolerance mechanism

Command:

smarty_manage check_stream_services —settings=settings.<settings name>

When configuring a fault-tolerant load-balanced service scheme, it is recommended to run this command every minute. The command checks services according to the check methods configured in the properties of the streaming service.

Monitoring

Stream monitoring module analyzers polling and alarming on accidents

Command:

smarty_manage check_streams —settings=settings.<settings name>

It is recommended to run every 1-5 minutes to keep the data on the flow monitoring page up to date.

Statistics

Collecting and storing statistics for every client

Command:

smarty_manage save_stats —settings=settings.<settings name>

This command collects statistics on customers (number of customers, maximum number of online customers, number of renewed customers, number of customers who changed the basic tariff, etc.) and statistics on transactions. The statistics can be viewed at: smarty.example.com/viewstats/customers_dynamic/.It is recommended to run the command once a day.

Collecting additional statistics for the report on the number of users

Command:

smarty_manage collect_daily_stats —settings=settings.<settings name>

This command collects information that is used in payment reports, as well as in the “Payments today” and “Customers from whom payment was received” charts on the Customer Dynamics screen. The command must be run every day at the beginning of the day (recording time is stored in UTC+0).

Saving the maximum number of customers online for statistics

Command:

smarty_manage cache_max_online —settings=settings.<settings name>

This command checks the number of users online and stores it in cache if it is greater than the previous value. Statistics can be viewed at the link: smarty.example.com/viewstats/customers_dynamic/. You can run the command as often as you like, but at least once a day.

Caching data for “Customer Dynamics” charts

Command:

smarty_manage cache_customers_dynamic —settings=settings.<settings name>

Parameters:

—client_id — comma-separated list of client identifiers for which caching should be carried out. If nothing is passed as an argument, then data for all clients is cached.

It is recommended to run the command once an hour. For small databases, graphics will work quickly and correctly even without this command. When launched for the first time, the command may take a long time to execute (depending on the number of accounts, transactions and tariffs) due to the fact that data will be calculated for the entire last month. When running again, only data for the last day or hour will be calculated (data that has already been cached is not cached again). Since the command may take a long time to complete, it is recommended that you try it on one client first.

Clearing the statistics storage database from old data in Smarty

Command:

smarty_manage reports_remove_old_data —settings=settings.<settings name>

Parameters:

—days — data older than this number of days must be cleared.

—hours — data older than this number of hours must be cleared.

—force — forced execution of the command, ignoring questions for users.

The command allows you to delete statistical data used for plotting in order not to store data from, for example, a year ago.

Deleting old reports

Command:

smarty_manage delete_old_reports —save-days=30 —settings=settings.<settings name>

Parameters:—save-days — period of time in days for which reports must be saved.