How to shutdown if failed to unlock a luks device within a time period

I want something similar to Need to shut down my laptop after a timeout in initramfs / Laptop Issues / Arch Linux Forums, but I have no idea how to implement this. I am using systemd in initrd.