CRON tasks question : Newb tries to launch simple project RPi4+BalenaOS/Cloud+Screenly

Hi there,
I just started a personal project without any knowledge and know how to do it.
I discovered 3 days ago, the BalenaCloud Platform and created an account. I followed step by step the tutorial and successed to connect my new Raspberry Pi4 B model 4GB RAM with BalenaOS on it linked to the Cloud Platform. I made my first application with :

  • BalenaOS
  • Redis
  • srly-ose-celery
  • srly-ose-server
  • srly-ose-viewer
  • srly-ose-websocket

Everything works fine. I had some problems to fit the digital signage exactly with my HDMI FullHD cheap TV’s screen and it was hard to find how to change UTC time to get the right time in the Screenly browser alike (I used commands directly in srly-ose-viewer’s Terminal in the cloud interface).

sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Europe/Paris/etc/localtime

My question is how to add tasks in Celery with Redis (I guess) linked to the worker (beat???) to get a kind of cron jobs to switch on/off the screen by HDMI CEC every night and in the morning.
I can switch off HDMI and put TV in Standby and wake it up by using commands in Terminal, it works fine but I don’t have any idea how to make it automaticlly.

echo 'standby 0.0.0.0' | cec-client -s -d 1
echo 'on 0.0.0.0' | cec-client -s -d 1

The tasks could be :

0 6 * * * echo 'on 0.0.0.0' | cec-client -s -d 1 >/dev/null 2>&1
30 20 * * * echo 'standby 0.0.0.0' | cec-client -s -d 1 >/dev/null 2>&1

I made some research and I understand I have to put that kind of code somewhere, but I don’t know how and where to do it…

    from celery.schedules import crontab

    app.conf.beat_schedule = {
        # Executes every day in the morning at 6:00 a.m.
        'add-every-morning': {
            'task': 'tasks.add',
            'schedule': crontab(hour=6, minute=00, day_of_week=0-6),
            'args': (16, 16), // <-- Don't know what it means!!!
        },
    }

    from celery.schedules import crontab

    app.conf.beat_schedule = {
        # Executes every day at night at 8:30 p.m.
        'add-every-night': {
            'task': 'tasks.add',
            'schedule': crontab(hour=20, minute=30, day_of_week=0-6),   // 0=sunday
            'args': (16, 16), // <-- Don't know what it means!!!
        },
    }

app.conf.timezone = 'UTC' // ???? Europe/Paris (yes, I'm French)

Thank you in advance for your kind help!!

Hey @pesant

Bienvenue :slight_smile: !

  1. Regarding setting the timezone in your application container, you can set a service variable TZ with the desired value.

  2. As for setting up the cron job, you can possible achieve this with a cron task itself. I’m not sure how (and why) you would want to do it with celery?

You can find an example of a scheduler service here. In the example it switches on/off the backlight on a PiDisplay. You would have to use the respective commands you specified

I hope this helps. Let us know

1 Like

Hey @pesant

Bienvenue :slight_smile: !

  1. Regarding setting the timezone in your application container, you can set a service variable TZ with the desired value.
  2. As for setting up the cron job, you can possible achieve this with a cron task itself. I’m not sure how (and why) you would want to do it with celery?

You can find an example of a scheduler service here. In the example it switches on/off the backlight on a PiDisplay. You would have to use the respective commands you specified

I hope this helps. Let us know

Hi @rahul-thakoor!
Thanx to welcome me! :slight_smile:

Regarding setting the timezone in your application container, you can set a service variable TZ with the desired value.

Yep, I get it, saw it by myslef few days ago and related to that post below, another expert like you confimed too few hours after I changed my configuration.

Concerning cron task, cron doesn’t work for me and because of that :

(at the end of discussion, specially from vpertesson)

So, thank you to re-open reflections about it and considering that possibility…
I have to try and adapt the code below to my wishes:

#!/bin/bash

if [ ! -z ${ENABLE_BACKLIGHT_TIMER+x} ] && [ "$ENABLE_BACKLIGHT_TIMER" -eq "1" ]

then

  (crontab -l; echo "${BACKLIGHT_ON:-0 8 * * *} /usr/src/backlight_on.sh") | crontab -

  (crontab -l; echo "${BACKLIGHT_OFF:-0 23 * * *} /usr/src/backlight_off.sh") | crontab -

fi

crond -f

I also saw that too:

Could you send me a simple procedure to make it?

1/ create my own scheduler script with vsCode, Atom etc…
a) start.sh ← cron job
b) hdmi_standby.sh ← CEC-CLIENT bash command
c) hdmi_on.sh

2/ push it on my device with Balena-CLI

Do I have to have another container docker as scheduler in your example or I have to modify an actual one (srly-*)?

Thank you very much!

Hi Christophe, sorry for the delayed reply…I did find another example we have for Cron Jobs, located here: GitHub - balena-io-playground/cron-example: Simple resin.io cron example.

In the Dockerfile, you can see how it is implemented: cron-example/Dockerfile.template at master · balena-io-playground/cron-example · GitHub

Hope that helps, thanks!

Hi @dtischler,

I will check this in hurry. Thanx for the links, I guess it will answer all my cron problems.

See you!

Hi again @dtischler,

Do you know how and where I can add it to my actual project?
(Which service I have to choose? How to implement that code in actual code?)

Thank you in advance!

Hi Christophe, sorry to say, but no I do not have any idea where in your codebase you would need to introduce this…you might have better luck asking over on the Screenly Forums, as their community likely has more experience with this type of a topic.

Hey @pesant
With respect to this:

Could you send me a simple procedure to make it?
1/ create my own scheduler script with vsCode, Atom etc…
a) start.sh ← cron job
b) hdmi_standby.sh ← CEC-CLIENT bash command
c) hdmi_on.sh
2/ push it on my device with Balena-CLI
Do I have to have another container docker as scheduler in your example or I have to modify an actual one (srly-*)?

I would suggest you add another service for the scheduler similar to what we have done in balenaDash. You can find the scheduler files here. You would need to modify your docker-compose file to include the service in the services section. Assuming you copied the files to a directory called scheduler, the following should work:

  scheduler:
    restart: always
    build: ./scheduler
    privileged: true

ofcourse, you will have to modify the backlight_on.sh and backlight_off.sh file to use the cec-client commands

Hope this helps

Thanks