• Overview
    Key features
    • Observability
    • Auto-scaling
    • Multiframework
    • Security
    Frameworks
    • Django
    • Next.js
    • Drupal
    • WordPress
    • Symfony
    • Magento
    • See all frameworks
    Languages
    • PHP
    • Python
    • Node.js
    • Ruby
    • Java
    • Go
  • Industries
    • Consumer Goods
    • Media/Entertainment
    • Higher Education
    • Government
    • Ecommerce
  • Pricing
  • Featured articles
    • Switching to Platform.sh can help IT/DevOps organizations drive 219% ROI
    • Organizations, the ultimate way to manage your users and projects
  • Support
  • Docs
  • Login
  • Request a demo
  • Free Trial
Meet Upsun. The new, self-service, fully managed PaaS, powered by Platform.sh.Try it now
Blog
Cover image

Announcing cancellable activities and crons

cronactivities
14 March, 2022
Chad Carlson
Chad Carlson
Manager, Developer Relations

Feature announcement: You can now cancel Platform.sh activities through the CLI and management console.

Last year we released activity scripts, custom scripts that you can upload to your projects to run in response to any project or environment activity. In March we announced parallel activities, a queue that allows two simultaneous processes across your environments.

Today we're announcing another change to your activities—you can now cancel them. We’ve extended our API so that pending activities can be cancelled through the management console and the CLI if they’re running longer than you'd expect them to. Additionally, in_progress crons can also be cancelled while they’re running.

Cancellable activities give you even greater control over your project's events. To use the feature, just run platform activity:cancel ACTIVITY_ID with the CLI. (You can always retrieve the unique ACTIVITY_ID and its current status withplatform activity:list.)

Cancellable crons

Crons play an important role in your applications, and we’ve spent some time in the past covering how they should be scheduled, and whether they should be scheduled with crons or run on worker containers. For a long time, this has been the syntax for crons in your .platform.app.yaml file:

crons:
  mycommand:
    spec: "*/19 * * * *"
    cmd: <command here>

With this definition, you've scheduled a command to run every multiple of 19 minutes after the hour, right after the build phase (the file system is completely read-only, and there are no mounts) under the environment.cron activity type.

To allow you to define commands for cancelling crons, we’ve changed their syntax in .platform.app.yaml:

crons:
  mycommand:
    spec: "*/19 * * * *"
    commands:
      start: <command here>
      stop: <command here>
    shutdown_timeout: 10

The first change you'll see is that the cmd key has been moved to commands.start key. Since it's replicating the previous cmd attribute, it's the only required definition in command. Same as before, everything defined in commands.start will run when the cron is triggered.

Stopping crons gracefully

There are also two new keys available: commands.stop and shutdown_timeout. commands.stop allows you to define a way to shut down the cron task—finishing an active item in a large list of tasks, for example—gracefully. With this definition in place, you can cancel a running cron task using that stop command through the management console by selecting the Stop run option from the activity's dropdown.

Cancelling a cron job in the platform.sh console

With the CLI you can retrieve the currently running cron's ID with the platform activity:list command and then cancel it using platform activity:cancel ACTIVITY_ID. It’s optional, and If you don't provide a stop command, cancelling the activity will send a SIGTERM signal to the process.

The last new attribute, shutdown_timeout (which is also optional), introduces an automatic safeguard against long-running crons. If a timeout is not specified the default value of the timeout is 10, which will send a SIGKILL to the process to force terminate the cron after it has run for 10 seconds.

Together these enhancements make your crons more configurable and better controlled. (But don’t worry, we’ll still continue to support the legacy cmd syntax.)

Get the latest Platform.sh news and resources
Subscribe

Related Content

Iterate faster with Improved Cancelable Activities

Iterate faster with Improved Cancelable Activities

Company
AboutSecurity and complianceTrust CenterCareersPressContact us
Thank you for subscribing!
  •  
Field required
Leader Winter 2023
System StatusPrivacyTerms of ServiceImpressumWCAG ComplianceAcceptable Use PolicyManage your cookie preferencesReport a security issue
© 2024 Platform.sh. All rights reserved.
Supported by Horizon 2020's SME Instrument - European Commission 🇪🇺